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
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
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
}
/** 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
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();
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) {
sigaction(SIGBUS,&sig,0);
sigaction(SIGSEGV,&sig,0);
sigaction(SIGFPE,&sig,0);
+ signal(SIGPIPE, SIG_IGN);
}
#ifdef THREADS