ecere/drivers/Android: Tweaks to run with latest Android SDK/NDK on Nexus 9
[sdk] / ecere / src / net / Service.ec
index ed3e336..3b5af5a 100644 (file)
@@ -1,19 +1,22 @@
-#define __statement __extension__   // To compile for Android/X86 (Need to add support to eC)
-                                    // Also had to add __extension__ to __swap16md macro in endian.h
+#ifdef __statement
+#undef __statement
+#endif
+#define __statement(x) __extension__(x)  // To compile for Android/X86 (Need to add support to eC)
+                                         // Also had to add __extension__ to __swap16md macro in endian.h
 namespace net;
 
 #ifndef ECERE_NONET
 
 #if defined(__WIN32__)
-
+#define SOCKLEN_TYPE int
 #define WIN32_LEAN_AND_MEAN
 #define String _String
 #include <winsock.h>
 #undef String
-static WSADATA wsaData;
 
 #elif defined(__unix__) || defined(__APPLE__)
 default:
+#define SOCKLEN_TYPE socklen_t
 #define set _set
 #define uint _uint
 #include <sys/time.h>
@@ -41,6 +44,14 @@ typedef struct in_addr IN_ADDR;
 
 import "network"
 
+#ifdef __ANDROID__
+// TOFIX:
+#undef ntohs
+#undef htons
+#define ntohs(x) (x)
+#define htons(x) (x)
+#endif
+
 public class Service
 {
 public:
@@ -59,6 +70,9 @@ public:
    #if defined(__WIN32__) || defined(__unix__) || defined(__APPLE__)
       SOCKET s;
 
+      if(this.s != -1)
+         return false; // Already started
+
    #ifdef DEBUG_SOCKETS
       Log("[P] [NStartService]\n");
    #endif
@@ -89,7 +103,7 @@ public:
                sockets.Clear();
 
                // Fix up the links/offsets here...
-               sockets.offset = (uint)&((Socket)0).prev;
+               sockets.offset = (uint)(uintptr)&((Socket)0).prev;
 
                FD_SET(s, &network.readSet);
                FD_SET(s, &network.exceptSet);
@@ -170,7 +184,7 @@ public:
                {
                   SOCKET s;
                   SOCKADDR_IN a;
-                  int addrLen = sizeof(a);
+                  SOCKLEN_TYPE addrLen = sizeof(a);
                   s = accept(this.s,(SOCKADDR *)&a,&addrLen);
                   closesocket(s);
                }