added support for CuBox (http://www.solid-run.com)
[deb_libcec.git] / src / lib / platform / posix / os-socket.h
index 30be947159d2fe9c64ed90f30be9e8fa7ee31799..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>
@@ -76,7 +77,7 @@ namespace PLATFORM
     if (socket == INVALID_SOCKET_VALUE)
     {
       *iError = EINVAL;
-      return -1;
+      return -EINVAL;
     }
 
     ssize_t iBytesWritten(0);
@@ -90,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;
     }
@@ -121,7 +122,7 @@ namespace PLATFORM
     if (socket == INVALID_SOCKET_VALUE)
     {
       *iError = EINVAL;
-      return -1;
+      return -EINVAL;
     }
 
     if (iTimeoutMs > 0)
@@ -150,7 +151,7 @@ namespace PLATFORM
       if (returnv == -1)
       {
         *iError = errno;
-        return -1;
+        return -errno;
       }
       else if (returnv == 0)
       {
@@ -161,7 +162,7 @@ namespace PLATFORM
       if (returnv == -1)
       {
         *iError = errno;
-        return -1;
+        return -errno;
       }
 
       iBytesRead += returnv;
@@ -172,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
@@ -210,7 +225,7 @@ namespace PLATFORM
     if (socket == INVALID_SOCKET_VALUE)
     {
       *iError = EINVAL;
-      return -1;
+      return -EINVAL;
     }
 
     if (iTimeoutMs > 0)