cec: fixed - ensure that the correct libCEC version is set after initialising the...
[deb_libcec.git] / src / lib / platform / posix / serialport.cpp
index 5557064555be90200cc2eeb7873522f6c1de9359..cefc21201ef03ee41d17feea11e5cdc3aac9e529 100644 (file)
@@ -37,7 +37,7 @@
 #include "../util/baudrate.h"
 #include "../posix/os-socket.h"
 
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__FreeBSD__)
 #ifndef XCASE
 #define XCASE  0
 #endif
@@ -53,29 +53,32 @@ using namespace PLATFORM;
 
 void CSerialSocket::Close(void)
 {
-  SocketClose(m_socket);
+  if (IsOpen())
+    SocketClose(m_socket);
 }
 
 void CSerialSocket::Shutdown(void)
 {
-  SocketClose(m_socket);
+  if (IsOpen())
+    SocketClose(m_socket);
 }
 
 ssize_t CSerialSocket::Write(void* data, size_t len)
 {
-  return SocketWrite(m_socket, &m_iError, data, len);
+  return IsOpen() ? SocketWrite(m_socket, &m_iError, data, len) : -1;
 }
 
 ssize_t CSerialSocket::Read(void* data, size_t len, uint64_t iTimeoutMs /* = 0 */)
 {
-  return SocketRead(m_socket, &m_iError, data, len, iTimeoutMs);
+  return IsOpen() ? SocketRead(m_socket, &m_iError, data, len, iTimeoutMs) : -1;
 }
 
 //setting all this stuff up is a pain in the ass
 bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
 {
   iTimeoutMs = 0;
-  CLockObject lock(m_mutex);
+  if (IsOpen())
+    return false;
 
   if (m_iDatabits != SERIAL_DATA_BITS_FIVE && m_iDatabits != SERIAL_DATA_BITS_SIX &&
       m_iDatabits != SERIAL_DATA_BITS_SEVEN && m_iDatabits != SERIAL_DATA_BITS_EIGHT)