more code
authorbdemsky <bdemsky>
Tue, 6 Nov 2007 07:21:39 +0000 (07:21 +0000)
committerbdemsky <bdemsky>
Tue, 6 Nov 2007 07:21:39 +0000 (07:21 +0000)
Robust/src/Benchmarks/Jhttpp2/Java/Jhttpp2ClientInputStream.java
Robust/src/Benchmarks/Jhttpp2/Java/Jhttpp2HTTPSession.java
Robust/src/ClassLibrary/SocketInputStream.java
Robust/src/Runtime/thread.c

index 10562fd4a975a63a295c782e22c9b5217d783e5e..39b229bd9bfb2c00e41b21b2c42d9e3b23d1fe43 100755 (executable)
@@ -80,7 +80,8 @@ public class Jhttpp2ClientInputStream extends BufferedInputStream {
        content_len = 0;\r
        boolean start_line=true;\r
        buf = getLine(); // reads the first line\r
-       \r
+       if (buf==null)\r
+           return -2;\r
        boolean cnt=true;\r
        while (lread>2&&cnt) {\r
            if (start_line) {\r
@@ -172,6 +173,8 @@ public class Jhttpp2ClientInputStream extends BufferedInputStream {
                header_length+=lread;\r
            }\r
            buf=getLine();\r
+           if (buf==null)\r
+               return -2;\r
        }\r
        rq+=buf; //adds last line (should be an empty line) to the header String\r
        header_length+=lread;\r
@@ -211,8 +214,11 @@ public class Jhttpp2ClientInputStream extends BufferedInputStream {
            if (l!=-1) {\r
                line+=(char)l;\r
                lread++;\r
-           } else\r
+           } else {\r
                cnt=false;\r
+               if (!line.equals(""))\r
+                   return null;\r
+           }\r
        }\r
        return line;\r
     }\r
index 5dde6bcf8736bb2a20aa896130fb9c9e4ca9d14b..66e80c4359d132054ab2df381565498b070f2b7a 100644 (file)
@@ -190,12 +190,14 @@ public class Jhttpp2HTTPSession extends Thread {
        }
     
     /** the main routine, where it all happens */
-    public void handleRequest() {
+    public int handleRequest() {
        InetAddress remote_host;
        Jhttpp2Read remote_in=null;
        int remote_port;
        byte[] b=new byte[65536];
        int numread=in.read(b);
+       if (numread==-2)
+           return -1;
        boolean cnt=true;
        while(cnt) { // with this loop we support persistent connections
            if (numread==-1) { // -1 signals an error
@@ -261,6 +263,8 @@ public class Jhttpp2HTTPSession extends Thread {
            if (cnt) {
                while(cnt) { // reads data from the client
                    numread=in.read(b);
+                   if (numread==-2)
+                       return -1;
                    if (numread!=-1) {
                        HTTP_out.write(b, 0, numread);
                        HTTP_out.flush();
@@ -273,7 +277,7 @@ public class Jhttpp2HTTPSession extends Thread {
        out.flush();
        if (!notConnected() && remote_in != null)
            remote_in.close(); // close Jhttpp2Read thread
-       return;
+       return 0;
     }
     /** connects to the given host and port */
     public void connect(InetAddress host,int port) {
index be7b58c353b5e3dba119a170721f0a652b00e3b9..43e4ed89e6221c7421125215f930a6c9d9aec30f 100644 (file)
@@ -7,7 +7,7 @@ public class SocketInputStream extends InputStream {
     public int read() {
        byte[] x=new byte[1];
        int len=s.read(x);
-       if (len==0)
+       if (len<=0)
            return -1;
        else return x[0];
     }
index 70cd784d6be150dd208b8719d100245185c0f028..235b4ed930feb21fbd20ecac8d33bf9a7a369068 100644 (file)
@@ -66,6 +66,7 @@ void initializethreads() {
   sigaction(SIGBUS,&sig,0);
   sigaction(SIGSEGV,&sig,0);
   sigaction(SIGFPE,&sig,0);
+  signal(SIGPIPE, SIG_IGN);
 }
 
 #ifdef THREADS