Revert "win32: implemented timeouts in serial socket reads"
[deb_libcec.git] / src / lib / platform / windows / serialport.cpp
index fe917255d5ad2e921b4ce628077ea42d57027c49..c0cdd936af9e586991ac2e6b463ca2df1674abc8 100644 (file)
@@ -48,14 +48,11 @@ void FormatWindowsError(int iErrorCode, CStdString &strMessage)
   }
 }
 
-bool CSerialSocket::SetTimeouts(serial_socket_t socket, int* iError, DWORD iTimeout)
+bool SetTimeouts(serial_socket_t socket, int* iError, bool bBlocking)
 {
   if (socket == INVALID_HANDLE_VALUE)
          return false;
 
-  if (iTimeout == m_iCurrentTimeout)
-    return true;
-
   COMMTIMEOUTS cto;
   if (!GetCommTimeouts(socket, &cto))
   {
@@ -63,9 +60,18 @@ bool CSerialSocket::SetTimeouts(serial_socket_t socket, int* iError, DWORD iTime
     return false;
   }
 
-  cto.ReadIntervalTimeout         = 0;
-  cto.ReadTotalTimeoutConstant    = iTimeout;
-  cto.ReadTotalTimeoutMultiplier  = 0;
+  if (bBlocking)
+  {
+    cto.ReadIntervalTimeout         = 0;
+    cto.ReadTotalTimeoutConstant    = 0;
+    cto.ReadTotalTimeoutMultiplier  = 0;
+  }
+  else
+  {
+    cto.ReadIntervalTimeout         = MAXDWORD;
+    cto.ReadTotalTimeoutConstant    = 0;
+    cto.ReadTotalTimeoutMultiplier  = 0;
+  }
 
   if (!SetCommTimeouts(socket, &cto))
   {
@@ -73,7 +79,6 @@ bool CSerialSocket::SetTimeouts(serial_socket_t socket, int* iError, DWORD iTime
     return false;
   }
 
-  m_iCurrentTimeout = iTimeout;
   return true;
 }
 
@@ -98,20 +103,7 @@ ssize_t CSerialSocket::Write(void* data, size_t len)
 
 ssize_t CSerialSocket::Read(void* data, size_t len, uint64_t iTimeoutMs /* = 0 */)
 {
-  if (IsOpen())
-  {
-    DWORD iTimeout((DWORD)iTimeoutMs);
-    if (iTimeout != iTimeoutMs)
-      return -1;
-
-    int iError(0);
-    if (!SetTimeouts(m_socket, &iError, iTimeout))
-      return -1;
-
-    return SerialSocketRead(m_socket, &m_iError, data, len, iTimeoutMs);
-  }
-
-  return -1;
+  return IsOpen() ? SerialSocketRead(m_socket, &m_iError, data, len, iTimeoutMs) : -1;
 }
 
 bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
@@ -161,7 +153,7 @@ bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
     return false;
   }
 
-  if (!SetTimeouts(m_socket, &m_iError, MAXDWORD))
+  if (!SetTimeouts(m_socket, &m_iError, false))
   {
     m_strError = "unable to set timeouts";
     FormatWindowsError(GetLastError(), m_strError);