Closing a socket gracefully
Posted on 1999-07-20
i have made a small server that immitates a http server, but only returns services that are supported in the server.
It could be done by individual CGI scripts, but for performance reason it is done like this.
Everything goes just fine, i get a request, proces it, and send a header back, followed by a lot of data (this being text/html)
After this i close the socket. At least, that's what it is supposed to do.. It doesnt do it gracefully, and the browser thinks the connection is reset by peer (while it should be a gracefull close, indicating end of document)
below is the code i use to close the socket:
(sock is a previously initialized socket)
well, what this does is close the socket alright.. cutting off all data that still needs to be send, and in general not being nice. Even though i think i called setsockopt ok..
Now, the one that see's the error and gives some code on how to correct it (probably only 4+ lines.. if it works i'm happy), and also explains what i did wrong, he/she will get the points :)
As you can see, i do NOT use MFC or OWL.. all plain API calls.. so please no fancy CSocket examples :-)