From 0897281dc19a1b702df425066d8df6250b7ffe4e Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 9 Nov 2006 22:57:26 +0000 Subject: [PATCH] small changes: 1) Revert TaskExample to its original form 2) WebServerExample/Socket change: Take it account that a long request could be split across two reads --- Robust/src/Tests/TaskExample.java | 8 ------- Robust/src/Tests/WebServerExample.java | 7 ++++--- Robust/src/Tests/WebServerSocket.java | 29 ++++++++++++++++++-------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Robust/src/Tests/TaskExample.java b/Robust/src/Tests/TaskExample.java index 6629a4a7..8ad37b34 100644 --- a/Robust/src/Tests/TaskExample.java +++ b/Robust/src/Tests/TaskExample.java @@ -14,14 +14,6 @@ class Example { * system to start the computation up */ task Startup(StartupObject s {initialstate}) { - String a = new String("hello\n"); - String b = new String("hello\n"); - System.printString(a); - System.printString(b); - System.printInt(b.hashCode()); - System.printString("\n"); - System.printInt(a.hashCode()); - for(int i=0;i<10;i++) { Example e=new Example() {needoperation}; e.x=i; diff --git a/Robust/src/Tests/WebServerExample.java b/Robust/src/Tests/WebServerExample.java index 09ed26d1..5d6fda09 100644 --- a/Robust/src/Tests/WebServerExample.java +++ b/Robust/src/Tests/WebServerExample.java @@ -23,13 +23,14 @@ task AcceptConnection(ServerSocket ss{SocketPending}) { task ProcessRequest(WebServerSocket web{IOPending && WebInitialize}) { //task ProcessRequest(WebServerSocket web{IOPending}) { System.printString("W> Inside ProcessRequest... \n"); - web.clientrequest(); - if(web.checktrans()==false) + if (web.clientrequest()) { + if(web.checktrans()==false) // Not special transaction , do normal filesending taskexit(web {WritePending, LogPending,!WebInitialize}); //Sets the WritePending and LogPending flag true - else + else // Invoke special inventory transaction taskexit(web {TransPending, LogPending,!WebInitialize}); + } } //Do the WriteIO on server socket and send the requested file to Client diff --git a/Robust/src/Tests/WebServerSocket.java b/Robust/src/Tests/WebServerSocket.java index 330764f6..411401c5 100644 --- a/Robust/src/Tests/WebServerSocket.java +++ b/Robust/src/Tests/WebServerSocket.java @@ -7,7 +7,8 @@ public class WebServerSocket extends Socket { //Filename requested by the client String filename; - String[] parsed; + String[] parsed; + String prefix; //Constructor public WebServerSocket(){ @@ -59,15 +60,25 @@ public class WebServerSocket extends Socket { } //Read the client request and extract the filename from it - public int clientrequest(){ + public boolean clientrequest(){ byte b1[] = new byte[1024]; - read(b1);//Read client request from web server socket - String clientreq = new String(b1); - int index = clientreq.indexOf('/');//Parse the GET client request to find filename - int end = clientreq.indexOf('H'); - filename = clientreq.subString((index+1), (end-1)); - System.printString("\n"); - return 0; + int numbytes=read(b1);//Read client request from web server socket + String curr=(new String(b1)).subString(0, numbytes); + if (prefix!=null) { + StringBuffer sb=new StringBuffer(prefix); + sb.append(curr); + curr=sb.toString(); + } + prefix=curr; + if(prefix.indexOf("\r\n\r\n")>=0) { + + int index = prefix.indexOf('/');//Parse the GET client request to find filename + int end = prefix.indexOf('H'); + filename = prefix.subString((index+1), (end-1)); + System.printString("\n"); + return true; + } + return false; } // Parse for the prefix in the client request -- 2.34.1