Share via


CAsyncSocket::OnSend

Llamado por el marco para notificar el socket que ahora puede enviar datos llamando a la función miembro de Enviar .

virtual void OnSend(
   int nErrorCode 
);

Parámetros

  • nErrorCode
    el error más reciente en un socket.Los códigos de error siguientes se aplican a la función miembro de OnSend :

    • Función de0 The ejecutada correctamente.

    • La implementación de Windows Sockets deWSAENETDOWN The detectó que produjo el subsistema de la red.

Comentarios

Para obtener más información, vea Windows Sockets: Notificaciones de socket.

Ejemplo

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

Requisitos

encabezado: afxsock.h

Vea también

Referencia

Clase de CAsyncSocket

Gráfico de jerarquía

CAsyncSocket::GetLastError

CAsyncSocket::OnAccept

CAsyncSocket::OnClose

CAsyncSocket::OnConnect

CAsyncSocket::OnOutOfBandData

CAsyncSocket::OnReceive

CAsyncSocket::Send