From: bdemsky Date: Fri, 16 Feb 2007 05:18:52 +0000 (+0000) Subject: support for non-bristlecone socket i/o X-Git-Tag: preEdgeChange~717 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=e6ac017633f019a593f1ea6ea6eeeb8edf91598f;p=IRC.git support for non-bristlecone socket i/o --- diff --git a/Robust/src/ClassLibrary/ServerSocketJava.java b/Robust/src/ClassLibrary/ServerSocketJava.java new file mode 100644 index 00000000..30e9638a --- /dev/null +++ b/Robust/src/ClassLibrary/ServerSocketJava.java @@ -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 index 00000000..ab7327e7 --- /dev/null +++ b/Robust/src/ClassLibrary/SocketJava.java @@ -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(); + } +} diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index 71907c57..8fd212eb 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -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"); diff --git a/Robust/src/Runtime/socket.c b/Robust/src/Runtime/socket.c index 460204e9..63416405 100644 --- a/Robust/src/Runtime/socket.c +++ b/Robust/src/Runtime/socket.c @@ -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); } diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 69ba9461..522b8690 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -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