remove some codes for scheduling
[IRC.git] / Robust / src / Runtime / socket.c
index 542f2deed8c455f7ac96c27fddca3d23e7fafe88..60709cd268a2706f18a6cc9b3c24b483907fa24d 100644 (file)
@@ -51,6 +51,15 @@ int CALL24(___Socket______nativeConnect____I__AR_B_I, int ___fd___, int ___port_
   return -1;
 }
 
+#ifdef TASK
+int CALL12(___Socket______nativeBindFD____I, int ___fd___, struct ___Socket___ * ___this___, int ___fd___) {
+  if (RuntimeHashcontainskey(fdtoobject, ___fd___))
+      RuntimeHashremovekey(fdtoobject, ___fd___);
+  RuntimeHashadd(fdtoobject, ___fd___, (int) VAR(___this___));
+  addreadfd(___fd___);
+}
+#endif
+
 
 int CALL12(___Socket______nativeBind_____AR_B_I, int ___port___,  struct ArrayObject * ___address___, int ___port___) {
   int fd;
@@ -192,6 +201,13 @@ int CALL12(___ServerSocket______createSocket____I, int port, struct ___ServerSoc
 #endif
   }
 
+#ifdef MAC
+        if (setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &n, sizeof (n)) < 0) {
+         perror("socket");
+         exit(-1);
+       }
+#endif
+
 #ifdef TASK
   fcntl(fd, F_SETFD, 1);
   fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
@@ -281,17 +297,23 @@ int CALL02(___ServerSocket______nativeaccept____L___Socket___,struct ___ServerSo
   return newfd;
 }
 
-void CALL02(___Socket______nativeWrite_____AR_B, struct ___Socket___ * ___this___, struct ArrayObject * ___b___) {
+void CALL24(___Socket______nativeWrite_____AR_B_I_I, int offset, int length, struct ___Socket___ * ___this___, struct ArrayObject * ___b___, int offset, int length) {
   int fd=VAR(___this___)->___fd___;
-  int length=VAR(___b___)->___length___;
-  char * charstr=((char *)& VAR(___b___)->___length___)+sizeof(int);
+  char * charstr=((char *)& VAR(___b___)->___length___)+sizeof(int)+offset;
   while(1) {
-    int bytewritten=write(fd, charstr, length);
-    if (bytewritten==-1&&errno==EAGAIN)
-      continue;
+    int offset=0;
+    int bytewritten;
+    while(length>0) {
+      bytewritten=write(fd, &charstr[offset], length);
+      if (bytewritten==-1&&errno!=EAGAIN)
+       break;
+      length-=bytewritten;
+      offset+=bytewritten;
+   }
 
-    if (bytewritten!=length) {
+    if (length!=0) {
       perror("ERROR IN NATIVEWRITE");
+      printf("error=%d remaining bytes %d\n",errno, length); 
     }
     break;
   }
@@ -308,13 +330,18 @@ int CALL02(___Socket______nativeRead_____AR_B, struct ___Socket___ * ___this___,
   struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
 #endif
 #endif
-  int byteread=read(fd, charstr, length);
+  int byteread=-1;
+
+  //  printf("Doing read on %d\n",fd);
+  do {
+    byteread=read(fd, charstr, length);
+  } while(byteread==-1&&errno==EINTR);
 #ifdef THREADS
 #ifdef PRECISE_GC
   restartaftergc(tmp);
 #endif
 #endif
-
+  
   {
     int i;
     for(i=0;i<byteread;i++) {
@@ -326,7 +353,7 @@ int CALL02(___Socket______nativeRead_____AR_B, struct ___Socket___ * ___this___,
 
   if (byteread<0) {
     printf("ERROR IN NATIVEREAD\n");
-    return 0;
+    perror("");
   }
 #ifdef TASK
   flagorand(VAR(___this___),0,0xFFFFFFFE);