From 679cd92f31fdfbbe28ad236c151c691ca037c46d Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 5 Oct 2006 00:00:03 +0000 Subject: [PATCH] checking in start of socket code --- Robust/src/ClassLibrary/ServerSocket.java | 16 ++++++++ Robust/src/ClassLibrary/Socket.java | 14 +++++++ Robust/src/Runtime/runtime.c | 49 +++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 Robust/src/ClassLibrary/ServerSocket.java create mode 100644 Robust/src/ClassLibrary/Socket.java diff --git a/Robust/src/ClassLibrary/ServerSocket.java b/Robust/src/ClassLibrary/ServerSocket.java new file mode 100644 index 00000000..0a1a1ea2 --- /dev/null +++ b/Robust/src/ClassLibrary/ServerSocket.java @@ -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 index 00000000..a2a06272 --- /dev/null +++ b/Robust/src/ClassLibrary/Socket.java @@ -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(); +} diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index abf51e71..64c2456e 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -18,6 +18,11 @@ jmp_buf error_handler; #include "Queue.h" #include "SimpleHash.h" #include "GenericHashtable.h" +#include +#include +#include + + #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;fdtask->numParameters;i++) { -- 2.34.1