CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2021

    Question about send() function.

    I am using blocking sockets, so the function send() will block if the buffer gets too full. I will be using the Win API function send() to send data over the network. After the data is successfully sent, I want my program to immediately call closesocket(). Can I be assured that even if send() doesn't block, that the data has been successfully sent and that it is therefore safe to call closesocket()? Or, if it doesn't block, might it return too quickly, and therefore allow the closesocket() function to be called too soon, resulting in the socket closing before the data actually gets sent, and thus preventing the data from actually being sent?

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    Re: Question about send() function.

    Didn't you read the documentation of send function?
    There is a pretty clear description:
    If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode. On nonblocking stream oriented sockets, the number of bytes written can be between 1 and the requested length, depending on buffer availability on both the client and server computers. The select, WSAAsyncSelect or WSAEventSelect functions can be used to determine when it is possible to send more data.
    Victor Nijegorodov

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