http connection lingers
Why does the http protocol linger at the end of the data transmission and how do you handle this.
I submit an HTTP GET request to a host, via sockets
I start a while loop using read() but at the end of the server's transmission read lingers, blocked I/O so to speak.
How should I go about handling this, right now I am using SIGALRM with a timer of 6 seconds RT but this is INCREDIBLY ineffective, how do normal browsers and other clients handle this anomaly?
it doesn't get stuck in the while, it gets stuck in the read(). I would like to know how I should handle these situations, I am thinking of using non-blocking I/O but there are issues with that as well.
printf("%d bytes read\n",n);
buf[n]=0; /* terminate string */
Send the "Connection: close" header to defeat Keep-Alive.
When keep-alive is in use, isn't it required that the Content-Length header be provided? Otherwise the client can't tell the difference between a stalled connection and the end of data.
So, the solution is to read exactly Content-Length bytes from the stream, then you know you are done and can close the socket.
yeah, the way to handle it is with the
in the GET Request
I just figured that out while playing with netcat.