//Listen for a request and accept request
task AcceptConnection(ServerSocket ss{SocketPending}) {
System.printString("W> Waiting for connection...\n");
- WebServerSocket web = new WebServerSocket() {!WritePending, !TransPending};
+ WebServerSocket web = new WebServerSocket() {!WritePending, !TransPending, WebInitialize};
ss.accept(web);
System.printString("W> Connected... \n");
}
// Process the incoming http request
-task ProcessRequest(WebServerSocket web{IOPending}) {
+task ProcessRequest(WebServerSocket web{IOPending && WebInitialize}) {
+//task ProcessRequest(WebServerSocket web{IOPending}) {
System.printString("W> Inside ProcessRequest... \n");
web.clientrequest();
if(web.checktrans()==false)
// Not special transaction , do normal filesending
- taskexit(web {WritePending, LogPending}); //Sets the WritePending and LogPending flag true
+ taskexit(web {WritePending, LogPending,!WebInitialize}); //Sets the WritePending and LogPending flag true
else
// Invoke special inventory transaction
- taskexit(web {TransPending, LogPending});
+ taskexit(web {TransPending, LogPending,!WebInitialize});
}
//Do the WriteIO on server socket and send the requested file to Client
} else { /* Error */
System.printString("T > Error - Unknown transaction\n");
}
- //Invoke operations
+ //Invoke close operations
web.close();
taskexit(web {!TransPending});
}
flag LogPending;
flag WritePending;
flag TransPending;
+ flag WebInitialize;
+
//Filename requested by the client
String filename;
String[] parsed;
byte b1[] = new byte[1024];
read(b1);//Read client request from web server socket
String clientreq = new String(b1);
- //System.printString(clientreq);
- //System.printString("\n");
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(filename);
System.printString("\n");
return 0;
}
}
}
-
+ //Parse for the substrings in the filename and use it to obtain the
+ //kind of operation, name of item, quantity of item, price of item
+ //e.g. trans_add_car_2_10000 is the filename
+ //store in the parsed[] string , add,car,2,1000
public int parseTransaction(){
int start = filename.indexOf('_');
String s = filename.subString(start+1);