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?
Code:
while((n=read(connfd,buf,MAXLINE))>0)
{
printf("%d bytes read\n",n);
buf[n]=0; /* terminate string */
if (write(outfd,buf,n)<=0)
{
fprintf(stderr,"write() error\n");
return 0;
}
}
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.