Click to See Complete Forum and Search --> : Fd_close
souldog
June 14th, 2003, 12:59 AM
Under what conditions is the FD_CLOSE event set for socket using events? Is it sent when the connection is lost do to network errors or during a hard disconnect? My socket wrapper will detect any error (Not WSAEWOULDBLOCK) and attempt a to reconnect, but I don't attempt to reconnect if it is a legitimate close. Is this going to work? Is WSAECONNRESET an event on which I should attempt a reconnect? Will a FD_CLOSE event follow this? In which case I wont to close the socket immediately and reconnect, because I don't try to reconnect if I receive a FD_CLOSE.
rxbagain
June 14th, 2003, 01:26 AM
You can check upon recieveing the FD_CLOSE if the socket is closed gracefully or not. Upon recieving FD_CLOSE, check the value of WSAGETSELECTERROR(lParam). If it is 0, then the soocket closure is graceful. If it is not zero, then there should be an error ocurred (WSAENETDOWN, WSAECONNRESET or WSAECONNABORTED) and you can reconnect to the server as appropriate.
Hope it will help you
souldog
June 14th, 2003, 01:30 AM
Thanks for the answer:)
Does this mean that I will receive a FD_CLOSE event for all errors?
And so this is the appropriate place to determine this. As of right now I terminate the socket thread if send or recv return an error and attempt a recconect. Am I correct in assuming that during a graceful closure both send and recieve will complete sucessfully?
I put a count on the number of attempted reconnects so it will stop trying after a specified number of attempts.
I should say that I don't terminate the socket thread, but close the socket and open a new on within the same thread.
rxbagain
June 14th, 2003, 01:48 AM
Not all errors generate FD_CLOSE, only those errors that will cause closure of sockets will generate this event. For example, WSAECONNRESET will send FD_CLOSE because the socket is really closed while WSAEINPROGRESS will not send FD_CLOSE event since the connection is still there.
During graceful closure, FD_CLOSE should be recieved only after all the received data has been read but MSDN says that we should still check for remaining data to avoid the possibility of losing data.
Hope it will clarify your concern
souldog
June 14th, 2003, 01:53 AM
Yes this really helps! Would a non-blocking socket every receive a WSAEINPROGRESS?
Mathew Joy
June 16th, 2003, 07:25 AM
Typically, this error is not found unless developing 16-bit winsock applications.
souldog
June 17th, 2003, 03:24 PM
Thanks.
runesvend
January 20th, 2006, 08:52 AM
I just found this thread by using the search engine and it has answered a lot of my questions, however I'm still not sure of some things. Here are my questions:
Is the FD_CLOSE message only received when the remote application closes the connection (either gracefully or abortively)? (Assuming that the local application doesn't issue WSAAsyncSelect on a closed socket or executes shutdown() on this socket)
If the above is true, I have an additional question.
Assume I'm either receiving or sending data with the local application (send() or recv() is looping). Let's say an error then happens on my connection which causes the FD_CLOSE message to be sent to the remote application. Do I then find out what has happened on my side by looking at WSAGetLastError() if send() or recv() returns SOCKET_ERROR (and WSAGetLastError doesn't equal WSAEWOULDBLOCK) as opposed to getting the error through the FD_CLOSE message?
I assume it isn't necessary to run shutdown() when an FD_CLOSE message is received since this indicates that the socket has already been shut down.
Perhaps it is my understandment of the MSDN library that isn't very good but I would like to be absolutely sure of this before deciding what to do in my program.
Thanks in advance,
-Rune
Andreas Masur
January 20th, 2006, 07:29 PM
[ Redirected thread ]
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.