virtual void OnSend( int nErrorCode );
Parameters
nErrorCode
The most recent error on a socket. The following error codes apply to the OnSend member function:
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 Windows Sockets: Socket Notifications 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 Overview | Class Members | Hierarchy Chart
See Also CAsyncSocket::GetLastError, CAsyncSocket::OnAccept, CAsyncSocket::OnClose, CAsyncSocket::OnConnect, CAsyncSocket::OnOutOfBandData, CAsyncSocket::OnReceive, CAsyncSocket::Send