CAsyncSocket::OnSend

virtualvoidOnSend(intnErrorCode**);**

Parameters

nErrorCode

The most recent error on a socket. The following error codes apply to the OnSend member function:

  • 0   The function executed successfully.

  • WSAENETDOWN   The Windows Sockets implementation detected that the network subsystem failed.

Remarks

Called by the framework to notify the socket that it can now send data by calling the Send member function.

 For more information, see the article in Visual C++ Programmer's Guide.

Example

// CMyAsyncSocket is derived from CAsyncSocket and defines the
// following variables:
//    CString      m_sendBuffer;   //for async send
//    int      m_nBytesSent;
//    int      m_nBytesBufferSize;

void CMyAsyncSocket ::OnSend(int nErrorCode)
{
   while (m_nBytesSent < m_nBytesBufferSize)
   {
      int dwBytes;

      if ((dwBytes = Send((LPCTSTR)m_sendBuffer + m_nBytesSent,
         m_nBytesBufferSize - m_nBytesSent)) == SOCKET_ERROR)
      {
         if (GetLastError() == WSAEWOULDBLOCK) break;
         else
         {
            TCHAR szError[256];
            wsprintf(szError, "Server Socket failed to send: %d",
               GetLastError());
            Close();
            AfxMessageBox (szError);
         }
      }
      else
      {
         m_nBytesSent += dwBytes;
      }
   }
   if (m_nBytesSent == m_nBytesBufferSize)
      {
         m_nBytesSent = m_nBytesBufferSize = 0;
         m_sendBuffer = "";
      }
   CAsyncSocket::OnSend(nErrorCode);
}

CAsyncSocket OverviewClass MembersHierarchy Chart

See Also   CAsyncSocket::GetLastError, CAsyncSocket::OnAccept, CAsyncSocket::OnClose, CAsyncSocket::OnConnect, CAsyncSocket::OnOutOfBandData, CAsyncSocket::OnReceive, CAsyncSocket::Send