CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005
    Posts
    18

    recv() error during closing app

    how to deal with problem of closing my socket program when recv() ing data?

    should I stop the recv() and flush the recv buffer so as to prevent recv() error?

  2. #2
    Join Date
    Aug 2001
    Location
    Stockholm, Sweden
    Posts
    1,664

    Re: recv() error during closing app

    Do you need to stop a pending recv()?

    Normally, you should know (by the application protocol) when to send and recv, and how much. Some application protocols, such as old HTTP version, don't specify content lengths, but rather close the socket when all data is sent or recv'd (the receiver gets zero back from recv(), known as graceful close).

    You can't "flush" the input or output stream. You can however shutdown the down-stream end of your socket with shutdown(s, SD_RECEIVE). Read more about shutdown() on MSDN.

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: recv() error during closing app

    Here's the MSDN recommendation for a graceful shutdown, as described at http://msdn.microsoft.com/library/en...shutdown_2.asp :
    Quote Originally Posted by MSDN
    To assure that all data is sent and received on a connected socket before it is closed, an application should use shutdown to close connection before calling closesocket. For example, to initiate a graceful disconnect:
    1. Call WSAAsyncSelect to register for FD_CLOSE notification.
    2. Call shutdown with how=SD_SEND.
    3. When FD_CLOSE received, call recv until zero returned, or SOCKET_ERROR.
    4. Call closesocket.
    Also check out the recommendations at "Graceful Shutdown, Linger Options, and Socket Closure" http://msdn.microsoft.com/library/en..._closure_2.asp

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured