-#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>
-static WSADATA wsaData;
+#undef String
#elif defined(__unix__) || defined(__APPLE__)
default:
+#define SOCKLEN_TYPE socklen_t
#define set _set
#define uint _uint
#include <sys/time.h>
import "network"
+#ifdef __ANDROID__
+// TOFIX:
+#undef ntohs
+#undef htons
+#define ntohs(x) (x)
+#define htons(x) (x)
+#endif
+
public class Service
{
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
{
if(!listen(s,5))
{
- // Fix up the links/offsets here...
network.mutex.Wait();
network.services.Add(this);
this.s = s;
destroyed = false;
sockets.Clear();
- sockets.offset = (uint)&((Socket)0).prev;
+ // Fix up the links/offsets here...
+ sockets.offset = (uint)(uintptr)&((Socket)0).prev;
FD_SET(s, &network.readSet);
FD_SET(s, &network.exceptSet);
- if(s >= network.ns)
+ if(s >= network.ns)
{
- network.ns = s+1;
+ network.ns = (int)(s+1);
network.socketsSemaphore.Release();
}
network.mutex.Release();
//FD_SET(s, &ws);
FD_SET(s, &es);
- selectResult = select(s+1, &rs, &ws, &es, &tvTO);
+ selectResult = select((int)(s+1), &rs, &ws, &es, &tvTO);
if(selectResult > 0)
{
if(FD_ISSET(s, &rs))
{
SOCKET s;
SOCKADDR_IN a;
- int addrLen = sizeof(a);
+ SOCKLEN_TYPE addrLen = sizeof(a);
s = accept(this.s,(SOCKADDR *)&a,&addrLen);
closesocket(s);
}