Sign in to follow this  
Matty_alan

Managing a client disconnection

Recommended Posts

Hey guys, I have a loop in my program that sends data to all my clients that looks like this value = send(clientx, buffer, bufsize, 0); However if send trys to send to a disconnected user it will return -1, error 10054(Connection Reset By Client) and then by the time it loops around to the next send I get Error 10055(Full Buffer). I done some poking around on "The Google" and found that the best way to mangage this is by using SO_LINGER, or TCP_NODELAY, using setockopt but iv'e slapped them into my program and nothing happened. So the question here is do I set the socket up like that after it errors, error 10054, sorta like this? value = send(clientx, buffer, bufsize, 0); Error = WSAGetLastError(); if(Error == 10054) { setsockopt(clientx, SO_LINGER, 1, buffer, buffersize); closesocket(clientx); } Or has the socket already been closed automaticly and i need to setsockopt's eariler in the program, like on the sockets creation? Do I need to still flush the buffer manually? or am I takling this the wrong way completely?? cheers Matty

Share this post


Link to post
Share on other sites
Quote:
Original post by Matty_alan
But if i didn't want to reconnect to the client and just flush the buffer clean

Flush to whom? Peer is gone. It's pinnin' for the Fjords. It is bereft of life. It is an Ex-Peer.

Quote:
Would I just shutdown the socket and close it?


Yes.

Share this post


Link to post
Share on other sites
Quote:
Original post by Antheus
Flush to whom? Peer is gone. It's pinnin' for the Fjords. It is bereft of life. It is an Ex-Peer.


Sorry i'm a bit of a noob, I think my terminology is wrong, I just want to clear the buffer to be used by the next command so it wont error,
could I just do something like buffer = NULL; or would that be doing something incredibly stupid and\or wouldn't work.

Share this post


Link to post
Share on other sites
Quote:
Original post by Matty_alan

Sorry i'm a bit of a noob, I think my terminology is wrong, I just want to clear the buffer to be used by the next command so it wont error,
could I just do something like buffer = NULL; or would that be doing something incredibly stupid and\or wouldn't work.


Network stack allocates internal buffers that it uses to coalesce data, hold it until confirmed, and similar. Whenever send is called, data from user buffer is copied into this internal buffer. The internal buffer is not accessible by user, it may be hidden deep inside of kernel.

In case of such send error there is no need to linger, since the peer is gone and nothing can be sent anymore. closesocket should be enough in this case. Linger might be used for clean disconnect to flush data, but that is somewhat tricky, since we're shutting down already, and linger might or might not complete in time, or might time out.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this