From: Lars Op den Kamp Date: Thu, 29 Mar 2012 10:36:23 +0000 (+0200) Subject: Revert "win32: implemented timeouts in serial socket reads" X-Git-Tag: upstream/2.2.0~1^2~31^2~33 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=15678787106be2ec2c412a8ad4c657821b3f9ff5;p=deb_libcec.git Revert "win32: implemented timeouts in serial socket reads" This reverts commit 5347b94bbd7455453754fd79b6aaa64aa368ce59. --- diff --git a/src/lib/platform/sockets/serialport.h b/src/lib/platform/sockets/serialport.h index fb4be19..bdd05b9 100644 --- a/src/lib/platform/sockets/serialport.h +++ b/src/lib/platform/sockets/serialport.h @@ -71,9 +71,6 @@ namespace PLATFORM public: CSerialSocket(const CStdString &strName, uint32_t iBaudrate, SerialDataBits iDatabits = SERIAL_DATA_BITS_EIGHT, SerialStopBits iStopbits = SERIAL_STOP_BITS_ONE, SerialParity iParity = SERIAL_PARITY_NONE) : CCommonSocket(INVALID_SERIAL_SOCKET_VALUE, strName), -#ifdef __WINDOWS__ - m_iCurrentTimeout(0), -#endif m_bIsOpen(false), m_iBaudrate(iBaudrate), m_iDatabits(iDatabits), @@ -99,9 +96,6 @@ namespace PLATFORM protected: #ifndef __WINDOWS__ struct termios m_options; - #else - bool SetTimeouts(serial_socket_t socket, int* iError, DWORD iTimeout); - DWORD m_iCurrentTimeout; #endif bool m_bIsOpen; diff --git a/src/lib/platform/windows/os-socket.h b/src/lib/platform/windows/os-socket.h index 86750c5..5174cba 100644 --- a/src/lib/platform/windows/os-socket.h +++ b/src/lib/platform/windows/os-socket.h @@ -95,8 +95,6 @@ namespace PLATFORM inline ssize_t SerialSocketRead(serial_socket_t socket, int *iError, void* data, size_t len, uint64_t iTimeoutMs /*= 0*/) { - *iError = 0; - if (len != (DWORD)len) { *iError = EINVAL; diff --git a/src/lib/platform/windows/serialport.cpp b/src/lib/platform/windows/serialport.cpp index fe91725..c0cdd93 100644 --- a/src/lib/platform/windows/serialport.cpp +++ b/src/lib/platform/windows/serialport.cpp @@ -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);