Export (0) Print
Expand All

CAsyncSocket::OnSend 

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


virtual void OnSend(
   int nErrorCode 
);

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.

// 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);
}

Community Additions

ADD
Show:
© 2014 Microsoft