CAsyncSocket::OnSend

调用由框架通知套接字则可以通过调用 Send 成员函数现在发送数据。

virtual void OnSend(
   int nErrorCode 
);

参数

  • nErrorCode
    在套接字的最新错误。以下错误代码应用于 OnSend 成员函数:

    • 0 成功执行的函数。

    • WSAENETDOWN Windows套接字实现检测网络子系统失败。

备注

有关更多信息,请参见 Windows套接字:存储通知

示例

// 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];
            _stprintf_s(szError, _T("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 = _T("");
   }

   CAsyncSocket::OnSend(nErrorCode);
}

要求

Header: afxsock.h

请参见

参考

CAsyncSocket选件类

层次结构图

CAsyncSocket::GetLastError

CAsyncSocket::OnAccept

CAsyncSocket::OnClose

CAsyncSocket::OnConnect

CAsyncSocket::OnOutOfBandData

CAsyncSocket::OnReceive

CAsyncSocket::Send