|
|
|
@ -386,25 +386,19 @@ allparsed:
@@ -386,25 +386,19 @@ allparsed:
|
|
|
|
|
|
|
|
|
|
io_wantread(s); |
|
|
|
|
|
|
|
|
|
for (;;) |
|
|
|
|
{ |
|
|
|
|
for (;;) { |
|
|
|
|
int64 i; |
|
|
|
|
io_wait(); |
|
|
|
|
|
|
|
|
|
while ((i=io_canread())!=-1) |
|
|
|
|
{ |
|
|
|
|
if (i==s) // ist es der serversocket?
|
|
|
|
|
{ |
|
|
|
|
while ((i=io_canread())!=-1) { |
|
|
|
|
if (i==s) { // ist es der serversocket?
|
|
|
|
|
int n; |
|
|
|
|
while ((n=socket_accept4(s,(void*)&ip,&port))!=-1) |
|
|
|
|
{ |
|
|
|
|
if (io_fd(n)) |
|
|
|
|
{ |
|
|
|
|
while ((n=socket_accept4(s,(void*)&ip,&port))!=-1) { |
|
|
|
|
if (io_fd(n)) { |
|
|
|
|
struct http_data* h=(struct http_data*)malloc(sizeof(struct http_data)); |
|
|
|
|
io_wantread(n); |
|
|
|
|
|
|
|
|
|
if (h) |
|
|
|
|
{ |
|
|
|
|
if (h) { |
|
|
|
|
byte_zero(h,sizeof(struct http_data)); |
|
|
|
|
h->ip=ip; |
|
|
|
|
taia_now(&t); |
|
|
|
@ -417,50 +411,47 @@ allparsed:
@@ -417,50 +411,47 @@ allparsed:
|
|
|
|
|
} else |
|
|
|
|
io_close(n); |
|
|
|
|
} |
|
|
|
|
if (errno==EAGAIN) |
|
|
|
|
if( errno==EAGAIN ) |
|
|
|
|
io_eagain(s); |
|
|
|
|
else |
|
|
|
|
carp("socket_accept4"); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
} else { |
|
|
|
|
char buf[8192]; |
|
|
|
|
struct http_data* h=io_getcookie(i); |
|
|
|
|
|
|
|
|
|
int l=io_tryread(i,buf,sizeof buf); |
|
|
|
|
if (l<=0) |
|
|
|
|
{ |
|
|
|
|
if (h) |
|
|
|
|
{ |
|
|
|
|
if( l <= 0 ) { |
|
|
|
|
if( h ) { |
|
|
|
|
array_reset(&h->r); |
|
|
|
|
free(h); |
|
|
|
|
} |
|
|
|
|
io_close(i); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
} else { |
|
|
|
|
array_catb(&h->r,buf,l); |
|
|
|
|
|
|
|
|
|
if (array_failed(&h->r)) |
|
|
|
|
if( array_failed(&h->r)) |
|
|
|
|
httperror(i,h,"500 Server Error","Request too long."); |
|
|
|
|
else if (array_bytes(&h->r)>8192) |
|
|
|
|
httperror(i,h,"500 request too long","You sent too much headers"); |
|
|
|
|
else if ((l=header_complete(h))) |
|
|
|
|
httpresponse(i,h); |
|
|
|
|
else { |
|
|
|
|
taia_now(&t); |
|
|
|
|
taia_addsec(&t,&t,OT_CLIENT_TIMEOUT); |
|
|
|
|
io_timeout(i,t); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while ((i=io_canwrite())!=-1) |
|
|
|
|
{ |
|
|
|
|
while ((i=io_canwrite())!=-1) { |
|
|
|
|
struct http_data* h=io_getcookie(i); |
|
|
|
|
|
|
|
|
|
int64 r=iob_send(i,&h->iob); |
|
|
|
|
if (r==-1) |
|
|
|
|
io_eagain(i); |
|
|
|
|
else |
|
|
|
|
if ((r<=0)||(h->iob.bytesleft==0)) |
|
|
|
|
{ |
|
|
|
|
if ((r<=0)||(h->iob.bytesleft==0)) { |
|
|
|
|
iob_reset(&h->iob); |
|
|
|
|
free(h); |
|
|
|
|
io_close(i); |
|
|
|
|