--- /dev/null
+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();
+
+}
--- /dev/null
+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();
+ }
+}
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");
#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) {
}
/* Store the fd/socket object mapping */
+#ifdef TASK
RuntimeHashadd(fdtoobject, fd, (int) VAR(___this___));
addreadfd(fd);
+#endif
return fd;
}
#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;
}
}
break;
}
- // flagorand(VAR(___this___),0,0xFFFFFFFE);
}
int CALL02(___Socket______nativeRead_____AR_B, struct ___Socket___ * ___this___, struct ArrayObject * ___b___) {
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);
}
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
gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \
tmpbuilddirectory/methods.c $FILES -o $MAINFILE.bin
-exit
-
-
+exit
\ No newline at end of file