start of new file
[IRC.git] / Robust / src / Runtime / socket.c
index e9ce2ffe2548ce2cec2eb7f9b4ad6039c8093b2f..bb84411ddf125d2f02b3105597f6f86542994e0a 100644 (file)
@@ -1,17 +1,23 @@
 #include "runtime.h"
 #include "structdefs.h"
-#include <sys/socket.h>
 #include <fcntl.h>
+#ifndef RAW
+#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <strings.h>
-#include <errno.h>
 #include <netdb.h>
+#endif
+#include <errno.h>
 #include "SimpleHash.h"
 #include "GenericHashtable.h"
 
-extern struct RuntimeHash *fdtoobject;
+struct RuntimeHash *fdtoobject;
 
 int CALL24(___Socket______nativeConnect____I__AR_B_I, int ___fd___, int ___port___, struct ___Socket___ * ___this___, int ___fd___, struct ArrayObject * ___address___ ,int ___port___) {
+#ifdef RAW
+       // not supported in RAW version
+       return -1;
+#else
   struct sockaddr_in sin;
   int rc;
   
@@ -19,7 +25,7 @@ int CALL24(___Socket______nativeConnect____I__AR_B_I, int ___fd___, int ___port_
   sin.sin_family= AF_INET;
   sin.sin_port=htons(___port___);
   sin.sin_addr.s_addr=htonl(*(int *)(((char *)&VAR(___address___)->___length___)+sizeof(int)));
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
 #ifdef PRECISE_GC
   struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
 #endif
@@ -27,7 +33,7 @@ int CALL24(___Socket______nativeConnect____I__AR_B_I, int ___fd___, int ___port_
   do {
     rc = connect(___fd___, (struct sockaddr *) &sin, sizeof(sin));
   } while (rc<0 && errno==EINTR); /* repeat if interrupted */
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
 #ifdef PRECISE_GC
   restartaftergc(tmp);
 #endif
@@ -49,6 +55,7 @@ int CALL24(___Socket______nativeConnect____I__AR_B_I, int ___fd___, int ___port_
  error:
   close(___fd___);
   return -1;
+#endif
 }
 
 #ifdef TASK
@@ -62,6 +69,10 @@ int CALL12(___Socket______nativeBindFD____I, int ___fd___, struct ___Socket___ *
 
 
 int CALL12(___Socket______nativeBind_____AR_B_I, int ___port___,  struct ArrayObject * ___address___, int ___port___) {
+#ifdef RAW
+       // not supported in RAW version
+       return -1;
+#else
   int fd;
   int rc;
   socklen_t sa_size;
@@ -112,9 +123,15 @@ int CALL12(___Socket______nativeBind_____AR_B_I, int ___port___,  struct ArrayOb
   exit(-1);
 #endif
 #endif
+#endif
 }
 
-struct ArrayObject * CALL01(___InetAddress______getHostByName_____AR_B, struct ___ArrayObject___ * ___hostname___) {
+struct ArrayObject * CALL01(___InetAddress______getHostByName_____AR_B, struct ArrayObject * ___hostname___) {
+#ifdef RAW
+       // not supported in RAW version
+       return NULL;
+#else
+//struct ArrayObject * CALL01(___InetAddress______getHostByName_____AR_B, struct ___ArrayObject___ * ___hostname___) {
   int length=VAR(___hostname___)->___length___;
   int i,j,n;
   char * str=malloc(length+1);
@@ -154,10 +171,15 @@ struct ArrayObject * CALL01(___InetAddress______getHostByName_____AR_B, struct _
   }
   
   return arraybytearray;
+#endif
 }
 
 
 int CALL12(___ServerSocket______createSocket____I, int port, struct ___ServerSocket___ * ___this___, int port) {
+#ifdef RAW
+       // not supported in RAW version
+       return -1;
+#else
   int fd;
 
   int n=1;
@@ -255,20 +277,25 @@ int CALL12(___ServerSocket______createSocket____I, int port, struct ___ServerSoc
   addreadfd(fd);
 #endif
   return fd;
+#endif
 }
 
 int CALL02(___ServerSocket______nativeaccept____L___Socket___,struct ___ServerSocket___ * ___this___, struct ___Socket___ * ___s___) {
+#ifdef RAW
+       // not supported in RAW version
+       return -1;
+#else
   struct sockaddr_in sin;
   unsigned int sinlen=sizeof(sin);
   int fd=VAR(___this___)->___fd___;
   int newfd;
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
 #ifdef PRECISE_GC
   struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
 #endif
 #endif
   newfd=accept(fd, (struct sockaddr *)&sin, &sinlen);
-#ifdef THREADS 
+#if defined(THREADS)||defined(DSTM)
 #ifdef PRECISE_GC
   restartaftergc(tmp);
 #endif
@@ -293,14 +320,17 @@ int CALL02(___ServerSocket______nativeaccept____L___Socket___,struct ___ServerSo
   RuntimeHashadd(fdtoobject, newfd, (int) VAR(___s___));
   addreadfd(newfd);
 #ifdef MULTICORE
-  flagorand(VAR(___this___),0,0xFFFFFFFE,objq4socketobj[corenum],numqueues4socketobj[corenum]);
-  enqueueObject(VAR(___this___), objq4socketobj[corenum], numqueues4socketobj[corenum]);
+  flagorand(VAR(___this___),0,0xFFFFFFFE,NULL,0);
+  enqueueObject(VAR(___this___), NULL, 0);
+  //flagorand(VAR(___this___),0,0xFFFFFFFE,objq4socketobj[corenum],numqueues4socketobj[corenum]);
+  //enqueueObject(VAR(___this___), objq4socketobj[corenum], numqueues4socketobj[corenum]);
 #else
   flagorand(VAR(___this___),0,0xFFFFFFFE);
   enqueueObject(VAR(___this___));
 #endif
 #endif
   return newfd;
+#endif
 }
 
 void CALL24(___Socket______nativeWrite_____AR_B_I_I, int offset, int length, struct ___Socket___ * ___this___, struct ArrayObject * ___b___, int offset, int length) {
@@ -318,8 +348,10 @@ void CALL24(___Socket______nativeWrite_____AR_B_I_I, int offset, int length, str
    }
 
     if (length!=0) {
+#ifndef RAW
       perror("ERROR IN NATIVEWRITE");
       printf("error=%d remaining bytes %d\n",errno, length); 
+#endif
     }
     break;
   }
@@ -331,7 +363,7 @@ int CALL02(___Socket______nativeRead_____AR_B, struct ___Socket___ * ___this___,
 
   char * charstr=malloc(length);
   
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
 #ifdef PRECISE_GC
   struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
 #endif
@@ -342,7 +374,7 @@ int CALL02(___Socket______nativeRead_____AR_B, struct ___Socket___ * ___this___,
   do {
     byteread=read(fd, charstr, length);
   } while(byteread==-1&&errno==EINTR);
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
 #ifdef PRECISE_GC
   restartaftergc(tmp);
 #endif
@@ -358,13 +390,17 @@ int CALL02(___Socket______nativeRead_____AR_B, struct ___Socket___ * ___this___,
 
 
   if (byteread<0) {
+#ifndef RAW
     printf("ERROR IN NATIVEREAD\n");
     perror("");
+#endif
   }
 #ifdef TASK
 #ifdef MULTICORE
-  flagorand(VAR(___this___),0,0xFFFFFFFE,objq4socketobj[corenum],numqueues4socketobj[corenum]);
-  enqueueObject(VAR(___this___),objq4socketobj[corenum],numqueues4socketobj[corenum]);
+  flagorand(VAR(___this___),0,0xFFFFFFFE,NULL,0);
+  enqueueObject(VAR(___this___), NULL, 0);
+  //flagorand(VAR(___this___),0,0xFFFFFFFE,objq4socketobj[corenum],numqueues4socketobj[corenum]);
+  //enqueueObject(VAR(___this___),objq4socketobj[corenum],numqueues4socketobj[corenum]);
 #else
   flagorand(VAR(___this___),0,0xFFFFFFFE);
   enqueueObject(VAR(___this___));
@@ -381,8 +417,10 @@ void CALL01(___Socket______nativeClose____, struct ___Socket___ * ___this___) {
   RuntimeHashremove(fdtoobject, fd, data);
   removereadfd(fd);
 #ifdef MULTICORE
-  flagorand(VAR(___this___),0,0xFFFFFFFE,objq4socketobj[corenum],numqueues4socketobj[corenum]);
-  enqueueObject(VAR(___this___),objq4socketobj[corenum],numqueues4socketobj[corenum]);
+  flagorand(VAR(___this___),0,0xFFFFFFFE,NULL,0);
+  enqueueObject(VAR(___this___), NULL, 0);
+  //flagorand(VAR(___this___),0,0xFFFFFFFE,objq4socketobj[corenum],numqueues4socketobj[corenum]);
+  //enqueueObject(VAR(___this___),objq4socketobj[corenum],numqueues4socketobj[corenum]);
 #else
   flagorand(VAR(___this___),0,0xFFFFFFFE);
   enqueueObject(VAR(___this___));