X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fplatform%2Fsockets%2Fsocket.h;h=f56d515c5e76676f95573555db07ad41523fe887;hb=5347b94bbd7455453754fd79b6aaa64aa368ce59;hp=9ef359679f1b0e48fb7634351d3f15cbbfe611d9;hpb=8637ad53b004d3e88e515fbf91ea4f7f17a11721;p=deb_libcec.git diff --git a/src/lib/platform/sockets/socket.h b/src/lib/platform/sockets/socket.h index 9ef3596..f56d515 100644 --- a/src/lib/platform/sockets/socket.h +++ b/src/lib/platform/sockets/socket.h @@ -40,11 +40,6 @@ #include "../posix/os-socket.h" #endif -/* Needed on Mac OS/X */ -#ifndef SOL_TCP -#define SOL_TCP IPPROTO_TCP -#endif - // Common socket operations namespace PLATFORM @@ -110,7 +105,7 @@ namespace PLATFORM public: CProtectedSocket(_Socket *socket) : m_socket(socket), - m_iUseCount(0) {} + m_bIsIdle(true) {} virtual ~CProtectedSocket(void) { @@ -156,19 +151,19 @@ namespace PLATFORM virtual bool IsBusy(void) { CLockObject lock(m_mutex); - return m_socket && m_iUseCount > 0; + return m_socket && !m_bIsIdle; } - virtual int GetUseCount(void) + virtual bool IsIdle(void) { CLockObject lock(m_mutex); - return m_iUseCount; + return m_socket && m_bIsIdle; } virtual ssize_t Write(void* data, size_t len) { if (!m_socket || !WaitReady()) - return EINVAL; + return -EINVAL; ssize_t iReturn = m_socket->Write(data, len); MarkReady(); @@ -179,7 +174,7 @@ namespace PLATFORM virtual ssize_t Read(void* data, size_t len, uint64_t iTimeoutMs = 0) { if (!m_socket || !WaitReady()) - return EINVAL; + return -EINVAL; ssize_t iReturn = m_socket->Read(data, len, iTimeoutMs); MarkReady(); @@ -198,7 +193,7 @@ namespace PLATFORM virtual int GetErrorNumber(void) { CLockObject lock(m_mutex); - return m_socket ? m_socket->GetErrorNumber() : EINVAL; + return m_socket ? m_socket->GetErrorNumber() : -EINVAL; } virtual CStdString GetName(void) @@ -213,27 +208,21 @@ namespace PLATFORM bool WaitReady(void) { CLockObject lock(m_mutex); - if (m_iUseCount > 0) - m_condition.Wait(m_mutex); - - if (m_iUseCount > 0) - return false; - - ++m_iUseCount; + m_condition.Wait(m_mutex, m_bIsIdle); + m_bIsIdle = false; return true; } void MarkReady(void) { CLockObject lock(m_mutex); - if (m_iUseCount > 0) - --m_iUseCount; - m_condition.Broadcast(); + m_bIsIdle = true; + m_condition.Signal(); } - _Socket *m_socket; - CMutex m_mutex; - CCondition m_condition; - int m_iUseCount; + _Socket * m_socket; + CMutex m_mutex; + CCondition m_condition; + bool m_bIsIdle; }; };