task acceptconnection(ServerSocket ss{SocketPending}) {
tag t=new tag(connection);
- Socket s=ss.accept(t);
+ MySocket ms=new MySocket(){}{t};
+ ss.accept(ms);
Jhttpp2HTTPSession js=new Jhttpp2HTTPSession() {first}{t};
Jhttpp2ClientInputStream jcis=new Jhttpp2ClientInputStream() {}{t};
}
-task requestfirst(Jhttpp2HTTPSession session {first}{connection tc}, Jhttpp2ClientInputStream jcis {}{connection tc}, Socket socket {IOPending}{connection tc}) {
+task requestfirst(Jhttpp2HTTPSession session {first}{connection tc}, Jhttpp2ClientInputStream jcis {}{connection tc}, MySocket socket {IOPending}{connection tc}) {
byte[] buf=new byte[10000];
int length=socket.read(buf);
String str=new String(buf, 0, length);
- System.printString("["+str+"]\n");
if (session.request!=null) {
str=session.request.concat(str);
}
}
}
-task request(Jhttpp2HTTPSession session {}{connection tc}, Jhttpp2ClientInputStream jcis {}{connection tc}, Socket socket {IOPending}{connection tc}, optional Request rold{!chained}{connection tc}) {
+task request(Jhttpp2HTTPSession session {!first}{connection tc}, Jhttpp2ClientInputStream jcis {}{connection tc}, MySocket socket {IOPending}{connection tc}, optional Request rold{!chained}{connection tc}) {
byte[] buf=new byte[10000];
int length=socket.read(buf);
- System.printString("length="+length+"\n");
if (session.request!=null)
System.printString(session.request+"\n");
if (length==0) {
+ socket.close();
taskexit;
} else if (length < 0 ) {
System.printString("ERROR\n");
taskexit;
}
String str=new String(buf, 0, length);
- System.printString("["+str+"]\n");
if (session.request!=null) {
str=session.request.concat(str);
session.request=str;
taskexit;
} else {
- System.printString("new Request\n");
session.request=str.substring(r.length(), str.length());
if (session.request.length()>0)
taskexit(session{more}, rold{chained}{ct});
taskexit(r{processed});
}
-task sendnext(optional Request rprev{received&&!done}{chained ct}, Request r{!processed}{chained ct}) {
+task sendnext(optional Request rprev{received&&!done}{chained ct}, Request r{!processed&&!first}{chained ct}) {
r.parseRequest();
- r.connect();
+ if (isavailable(rprev)&&rprev.remote_host_name!=null&&
+ rprev.remote_host_name.equals(r.remote_host_name)&&rprev.port==r.port) {
+ r.fd=rprev.fd;
+ r.nativeBindFD(r.fd);
+ } else
+ r.connect();
r.sendRequest();
taskexit(r{processed}, rprev{done});
}
if (length==0) {
//Done
taskexit(r{received});
+ } else if (length<0) {
+ r.close();
+ taskexit(r{received});
}
String str=new String(buf, 0, length);
if (r.response!=null) {
lastindex=nextindex;
}
if (bytes>0) {
- if ((lastindex+bytes)<str.length()) {
+ if ((lastindex+bytes)<=str.length()) {
r.response=str;
taskexit(r{received});
} else {
}
}
-task sendfirstresp(optional Request r{first && !sent && received}{connection tc}, Socket sock{}{connection tc}) {
- if (isavailable(r)) {
- System.printString(r.response);
+task sendfirstresp(optional Request r{first && !sent && received}{connection tc}, MySocket sock{}{connection tc}) {
+ if (isavailable(r)&&r.response!=null) {
sock.write(r.response.getBytes());
taskexit(r{sent});
} else {
}
}
-task sendresp(optional Request rprev {sent}{chained ct}, optional Request r{!sent && received}{chained ct, connection tc}, Socket sock{}{connection tc}) {
- if (isavailable(r)) {
- System.printString(r.response);
+task sendresp(optional Request rprev {sent}{chained ct}, optional Request r{!sent && received && !first}{chained ct, connection tc}, MySocket sock{}{connection tc}) {
+ if (isavailable(r)&&r.response!=null) {
sock.write(r.response.getBytes());
taskexit(r{sent});
} else {