support for non-bristlecone socket i/o
authorbdemsky <bdemsky>
Fri, 16 Feb 2007 05:18:52 +0000 (05:18 +0000)
committerbdemsky <bdemsky>
Fri, 16 Feb 2007 05:18:52 +0000 (05:18 +0000)
Robust/src/ClassLibrary/ServerSocketJava.java [new file with mode: 0644]
Robust/src/ClassLibrary/SocketJava.java [new file with mode: 0644]
Robust/src/Main/Main.java
Robust/src/Runtime/socket.c
Robust/src/buildscript

diff --git a/Robust/src/ClassLibrary/ServerSocketJava.java b/Robust/src/ClassLibrary/ServerSocketJava.java
new file mode 100644 (file)
index 0000000..30e9638
--- /dev/null
@@ -0,0 +1,28 @@
+public class ServerSocket {
+    /* File Descriptor */
+    int fd;
+
+    private native int createSocket(int port);
+
+    public ServerSocket(int port) {
+       this.fd=createSocket(port);
+    }
+    
+    public Socket accept() {
+       Socket s=new Socket();
+       int newfd=nativeaccept(s);
+       s.setFD(newfd);
+       return s;
+    }
+
+    /* Lets caller pass in their own Socket object. */
+    public void accept(Socket s) {
+       int newfd=nativeaccept(s);
+       s.setFD(newfd);
+    }
+
+    private native int nativeaccept(Socket s);
+    
+    public void close();
+
+}
diff --git a/Robust/src/ClassLibrary/SocketJava.java b/Robust/src/ClassLibrary/SocketJava.java
new file mode 100644 (file)
index 0000000..ab7327e
--- /dev/null
@@ -0,0 +1,27 @@
+public class Socket {
+    /* Data pending flag */
+    /* File Descriptor */
+    int fd;
+    
+    Socket() {
+    }
+    
+    int setFD(int filed) {
+       fd=filed;
+    }
+
+    public int read(byte[] b) {
+       return nativeRead(b);
+    }
+    public void write(byte[] b) {
+       nativeWrite(b);
+    }
+
+    private native int nativeRead(byte[] b);
+    private native void nativeWrite(byte[] b);
+    private native void nativeClose();
+
+    public void close() {
+       nativeClose();
+    }
+}
index 71907c575c6a075753e7a43e1f094e8c64245ef3..8fd212ebeb492d1c17e7e1fe6f910b7d387d3da4 100644 (file)
@@ -73,7 +73,10 @@ public class Main {
          readSourceFile(state, ClassLibraryPrefix+"StartupObject.java");
          readSourceFile(state, ClassLibraryPrefix+"Socket.java");
          readSourceFile(state, ClassLibraryPrefix+"ServerSocket.java");
-      } 
+      } else {
+         readSourceFile(state, ClassLibraryPrefix+"SocketJava.java");
+         readSourceFile(state, ClassLibraryPrefix+"ServerSocketJava.java");
+      }
 
       if (state.THREAD) {
          readSourceFile(state, ClassLibraryPrefix+"Thread.java");
index 460204e9f3cc732cd2309a2183fa3348c7c3c19e..63416405a384cd508ac89fd7744b3489c7541302 100644 (file)
@@ -37,8 +37,11 @@ int CALL12(___ServerSocket______createSocket____I, int port, struct ___ServerSoc
 #endif
     longjmp(error_handler, 6);
   }
+
+#ifdef TASK
   fcntl(fd, F_SETFD, 1);
   fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
+#endif
 
   /* bind to port */
   if (bind(fd, (struct sockaddr *) &sin, sizeof(sin))<0) { 
@@ -61,8 +64,10 @@ int CALL12(___ServerSocket______createSocket____I, int port, struct ___ServerSoc
   }
 
   /* Store the fd/socket object mapping */
+#ifdef TASK
   RuntimeHashadd(fdtoobject, fd, (int) VAR(___this___));
   addreadfd(fd);
+#endif
   return fd;
 }
 
@@ -81,11 +86,13 @@ int CALL02(___ServerSocket______nativeaccept____L___Socket___,struct ___ServerSo
 #endif
     longjmp(error_handler, 9);
   }
+#ifdef TASK
   fcntl(newfd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
-
   RuntimeHashadd(fdtoobject, newfd, (int) VAR(___s___));
   addreadfd(newfd);
   flagorand(VAR(___this___),0,0xFFFFFFFE);
+#endif
+
   return newfd;
 }
 
@@ -104,7 +111,6 @@ void CALL02(___Socket______nativeWrite_____AR_B, struct ___Socket___ * ___this__
     }
     break;
   }
-  //  flagorand(VAR(___this___),0,0xFFFFFFFE);
 }
 
 int CALL02(___Socket______nativeRead_____AR_B, struct ___Socket___ * ___this___, struct ArrayObject * ___b___) {
@@ -116,16 +122,20 @@ int CALL02(___Socket______nativeRead_____AR_B, struct ___Socket___ * ___this___,
   if (byteread<0) {
     printf("ERROR IN NATIVEREAD\n");
   }
+#ifdef TASK
   flagorand(VAR(___this___),0,0xFFFFFFFE);
+#endif
   return byteread;
 }
 
 void CALL01(___Socket______nativeClose____, struct ___Socket___ * ___this___) {
   int fd=VAR(___this___)->___fd___;
   int data;
+#ifdef TASK
   RuntimeHashget(fdtoobject, fd, &data);
   RuntimeHashremove(fdtoobject, fd, data);
   removereadfd(fd);
-  close(fd);
   flagorand(VAR(___this___),0,0xFFFFFFFE);
+#endif
+  close(fd);
 }
index 69ba9461057203947ee15cedc16e0f2965f2d4d0..522b8690bbe5d0b47728cc820eab1b6290b452db 100755 (executable)
@@ -149,19 +149,18 @@ fi # CHECKFLAG
 
 cd $CURDIR 
 
-
 INCLUDES="$INCLUDES -I$ROBUSTROOT/Runtime -I. -IRuntime/include \
 -I$BUILDDIR"
 
 FILES="$ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/file.c \
 $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c \
 $ROBUSTROOT/Runtime/option.c $ROBUSTROOT/Runtime/garbage.c \
-$ROBUSTROOT/Runtime/GenericHashtable.c"
+$ROBUSTROOT/Runtime/socket.c $ROBUSTROOT/Runtime/GenericHashtable.c"
 
 if $RECOVERFLAG
 then
 EXTRAOPTIONS="$EXTRAOPTIONS -DTASK"
-FILES="$FILES $ROBUSTROOT/Runtime/socket.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/checkpoint.c"
+FILES="$FILES tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/checkpoint.c"
 else
 FILES="$FILES $ROBUSTROOT/Runtime/thread.c"
 fi
@@ -174,6 +173,4 @@ fi
 
 gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \
 tmpbuilddirectory/methods.c $FILES -o $MAINFILE.bin
-exit
-
-
+exit
\ No newline at end of file