General recv() and FD_CLOSE question.

I'm developing a program for transferring files from one computer to another and I have a question regarding the behaviour of recv() and the FD_CLOSE message. The quote below is from MSDN's explanation of WSAAsyncSelect:

Originally Posted by MSDN-WSAAsyncSelect (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsaasyncselect_2.asp)
FD_CLOSE should only be posted after all data is read from a socket, but an application should check for remaining data upon receipt of FD_CLOSE to avoid any possibility of losing data.

Be aware that the application will only receive an FD_CLOSE message to indicate closure of a virtual circuit, and only when all the received data has been read if this is a graceful close. It will not receive an FD_READ message to indicate this condition.
Does the last part of this quote mean, that while receiving data upon FD_READ messages the connection could be closed but I wouldn't receive any more FD_READ messages since the connection has been closed. Since I don't receive any FD_READ messages I don't execute recv() and there is still data to be read on the socket and therefore I don't get an FD_CLOSE message?

Am I understanding this statement correctly?

In a simplified form my question is the following: When properly handling the FD_CLOSE message, is it necessary to take any action if recv() returns 0? Or will I on some point receive a FD_CLOSE message after recv() has returned 0?

Thanks,

-Rune
[1557 byte] By [runesvend] at [2007-11-19 18:21:58]
# 1 Re: General recv() and FD_CLOSE question.
There is some chapter in MSDN about graceful connection shutdown. I think you will find the answer there. http://windowssdk.msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/graceful_shutdown_linger_options_and_socket_closure_2.asp
philkr at 2007-11-9 13:52:11 >
# 2 Re: General recv() and FD_CLOSE question.
I have read the link you provided on graceful shutdown a couple of times already, but it doesn't seem to answer my question.

Is it necessary to read any pending data on a socket in order to receive the FD_CLOSE message?

(explanation of WSAAsyncSelect from MSDN)
Be aware that the application will only receive an FD_CLOSE message to indicate closure of a virtual circuit, and only when all the received data has been read if this is a graceful close. It will not receive an FD_READ message to indicate this condition.

This leads me to believe that if a graceful close is initiated, I have to receive all data on the socket before I get the FD_CLOSE message and I won't get any FD_READ messages to indicate that this is necessary. That is what I have trouble understanding.
runesvend at 2007-11-9 13:53:11 >