added support for CuBox (http://www.solid-run.com)
[deb_libcec.git] / src / lib / platform / posix / os-socket.h
index 468cc3deb4dfa075a60bff9cd2ca899e8ac0d5d8..9d98d9ad9285f3646046597b9ef1a71bc35f08d9 100644 (file)
  */
 
 
-#include "../os.h"
-#include "../util/timeutils.h"
+#include "lib/platform/os.h"
+#include "lib/platform/util/timeutils.h"
 #include <stdio.h>
 #include <fcntl.h>
+#include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 #include <netdb.h>
 #include <poll.h>
 
+/* Needed on Mac OS/X */
+#ifndef SOL_TCP
+#define SOL_TCP IPPROTO_TCP
+#endif
+
 namespace PLATFORM
 {
   // Standard sockets
@@ -71,7 +77,7 @@ namespace PLATFORM
     if (socket == INVALID_SOCKET_VALUE)
     {
       *iError = EINVAL;
-      return -1;
+      return -EINVAL;
     }
 
     ssize_t iBytesWritten(0);
@@ -85,19 +91,19 @@ namespace PLATFORM
       if (returnv < 0)
       {
         *iError = errno;
-        return -1;
+        return -errno;
       }
       else if (returnv == 0)
       {
         *iError = ETIMEDOUT;
-        return -1;
+        return -ETIMEDOUT;
       }
 
       returnv = write(socket, (char*)data + iBytesWritten, len - iBytesWritten);
       if (returnv == -1)
       {
         *iError = errno;
-        return -1;
+        return -errno;
       }
       iBytesWritten += returnv;
     }
@@ -116,7 +122,7 @@ namespace PLATFORM
     if (socket == INVALID_SOCKET_VALUE)
     {
       *iError = EINVAL;
-      return -1;
+      return -EINVAL;
     }
 
     if (iTimeoutMs > 0)
@@ -145,7 +151,7 @@ namespace PLATFORM
       if (returnv == -1)
       {
         *iError = errno;
-        return -1;
+        return -errno;
       }
       else if (returnv == 0)
       {
@@ -156,7 +162,7 @@ namespace PLATFORM
       if (returnv == -1)
       {
         *iError = errno;
-        return -1;
+        return -errno;
       }
 
       iBytesRead += returnv;
@@ -167,6 +173,20 @@ namespace PLATFORM
 
     return iBytesRead;
   }
+
+  inline int SocketIoctl(socket_t socket, int *iError, int request, void* data)
+  {
+    if (socket == INVALID_SOCKET_VALUE)
+    {
+      *iError = EINVAL;
+      return -1;
+    }
+
+    int iReturn = ioctl(socket, request, data);
+    if (iReturn < 0)
+      *iError = errno;
+    return iReturn;
+  }
   //@}
 
   // TCP
@@ -205,7 +225,7 @@ namespace PLATFORM
     if (socket == INVALID_SOCKET_VALUE)
     {
       *iError = EINVAL;
-      return -1;
+      return -EINVAL;
     }
 
     if (iTimeoutMs > 0)