checking in start of socket code
authorbdemsky <bdemsky>
Thu, 5 Oct 2006 00:00:03 +0000 (00:00 +0000)
committerbdemsky <bdemsky>
Thu, 5 Oct 2006 00:00:03 +0000 (00:00 +0000)
Robust/src/ClassLibrary/ServerSocket.java [new file with mode: 0644]
Robust/src/ClassLibrary/Socket.java [new file with mode: 0644]
Robust/src/Runtime/runtime.c

diff --git a/Robust/src/ClassLibrary/ServerSocket.java b/Robust/src/ClassLibrary/ServerSocket.java
new file mode 100644 (file)
index 0000000..0a1a1ea
--- /dev/null
@@ -0,0 +1,16 @@
+public class ServerSocket {
+    /* Socket pending flag */
+    flag SocketPending;    
+    /* File Descriptor */
+    int fd;
+
+    private native int createSocket(int port);
+
+    public ServerSocket(int port) {
+       this.fd=createSocket(port);
+    }
+    
+    public Socket accept();
+    public void close();
+
+}
diff --git a/Robust/src/ClassLibrary/Socket.java b/Robust/src/ClassLibrary/Socket.java
new file mode 100644 (file)
index 0000000..a2a0627
--- /dev/null
@@ -0,0 +1,14 @@
+public class Socket {
+    /* Data pending flag */
+    flag IOPending;    
+    /* File Descriptor */
+    int fd;
+    
+    private Socket(int fd) {
+       this.fd=fd;
+    }
+    
+    public int read(byte[] b);
+    public void write(byte[] b);
+    void close();
+}
index abf51e71d81f738847d392c4490f7a38a19d5180..64c2456e062a58a739342971d3ec6f284d95d9bc 100644 (file)
@@ -18,6 +18,11 @@ jmp_buf error_handler;
 #include "Queue.h"
 #include "SimpleHash.h"
 #include "GenericHashtable.h"
+#include <sys/select.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+
 #ifdef CONSCHECK
 #include "instrument.h"
 #endif
@@ -174,6 +179,26 @@ void myhandler(int sig, struct __siginfo *info, void *uap) {
   longjmp(error_handler,1);
 }
 
+
+fd_set readfds;
+int maxreadfd;
+struct RuntimeHash *fdtoobject;
+
+void addreadfd(int fd) {
+  if (fd>maxreadfd)
+    fd=maxreadfd;
+  FD_SET(fd, &readfds);
+}
+
+void removereadfd(int fd) {
+  FD_CLR(fd, &readfds);
+  if (maxreadfd==fd) {
+    maxreadfd--;
+    while(!FD_ISSET(maxreadfd, &readfds)&&maxreadfd>0)
+      maxreadfd--;
+  }
+}
+
 void executetasks() {
   void * taskpointerarray[MAXTASKPARAMS];
 
@@ -188,6 +213,11 @@ void executetasks() {
   sigaction(SIGSEGV,&sig,0);
   sigaction(SIGFPE,&sig,0);
 
+  /* Zero fd set */
+  FD_ZERO(&readfds);
+  maxreadfd=0;
+  fdtoobject=allocateRuntimeHash(100);
+
   /* Map first block of memory to protected, anonymous page */
   mmap(0, 0x1000, 0, MAP_SHARED|MAP_FIXED|MAP_ANON, -1, 0);
 
@@ -196,6 +226,25 @@ void executetasks() {
     struct QueueItem * qi=(struct QueueItem *) getTail(activetasks);
     struct taskparamdescriptor *tpd=(struct taskparamdescriptor *) qi->objectptr;
     int i;
+    struct timeval timeout={0,0};
+    fd_set tmpreadfds;
+    int numselect;
+    FD_COPY(&readfds, &tmpreadfds);
+    numselect=select(maxreadfd, &tmpreadfds, NULL, NULL, &timeout);
+    if (numselect>0) {
+      /* Process ready fd's */
+      int fd;
+      for(fd=0;fd<maxreadfd;fd++) {
+       if (FD_ISSET(fd, &readfds)) {
+         /* Set ready flag on object */
+         void * objptr;
+         if (RuntimeHashget(fdtoobject, fd,(int *) &objptr)) {
+           flagorand(objptr,1,0xFFFFFFFF); /* Set the first flag to 1 */
+         }
+       }
+      }
+    }
+    
     removeItem(activetasks, qi);
     
     for(i=0;i<tpd->task->numParameters;i++) {