All pastes #978376 Raw Edit

Something

public text v1 · immutable
·published 2008-04-09 14:51 UTC
rendered paste body
void Socket::Disconnect(bool bAbort)
{
    if(!m_bConnected)
        return;
	m_bConnected = false;
    if(bAbort)
        sLog.outDetail("<Socket %u> Abortively disconnected.", GetSocket());
    else
        sLog.outDetail("<Socket %u> Gracefully disconnected.", GetSocket());
    OnDisconnect();
	sLog.outString("After OnDisconnect() function");
    sSocketManager.RemoveSocket(this);
    if(m_SocketHandle != INVALID_SOCKET)
    {
        //////////////////////////////////////////////////////////////////////////
        //shutdown
        //To ensure that all data an application sends is received by the peer,
        //a well-written application should notify the receiver that no more data is to be sent.
        //SD_BOTH disables both sends and receives
        ::shutdown(m_SocketHandle, SD_BOTH);

        //////////////////////////////////////////////////////////////////////////
        //closesocket
        //The closesocket function closes a socket
        //Calling closesocket releases the socket descriptor and any further calls using the socket fail with WSAENOTSOCK.
        //If there are no other references to this socket, all resources associated with the descriptor are released.
        //This includes discarding any queued data.
        ::closesocket(m_SocketHandle);
    }
    m_SocketHandle = INVALID_SOCKET;
	sSocketManager.EraseSocket(this);
//	delete this;
sLog.outString("Disconnect function ended");
}