bool AuthSocket::send(const char* buf, size_t len)
{
    if (buf == NULL || len == 0)
        return true;
    
    GuardType Guard(m_OutBufferLock);
    
    if (m_OutBuffer->space() >= len)
    {
        // Put the packet on the buffer.
        if (m_OutBuffer->copy((char*)buf, len) == -1)
        {
            MANGOS_ASSERT(false);
            return false;
        }
    }
    else
    {
        // Enqueue the packet.
        sLog.outError("network write buffer is too small to accommodate packet. Disconnecting client");
        
        MANGOS_ASSERT(false);
        return false;
    }
    
    start_async_send();
    
    return true;
}
Beispiel #2
0
void Socket::on_write_complete( const boost::system::error_code& error,
                                     size_t bytes_transferred )
{
    if( error )
    {
        OnError( error );
        return;
    }

    GuardType Lock(m_OutBufferLock);

    m_OutActive = false;

    m_OutBuffer->rd_ptr( bytes_transferred );

    reset( *m_OutBuffer ); 

    start_async_send();
}
Beispiel #3
0
void MClient::start_async_send()
{
	if (!m_pNetClientBuffer->startAsyncSend())	// 如果 Client 不能发送数据
	{
		return;
	}

	boost::asio::async_write(socket_,
		boost::asio::buffer(m_pNetClientBuffer->m_sendSocketBuffer->getStorage(), m_pNetClientBuffer->m_sendSocketBuffer->size()),
		[this](boost::system::error_code ec, std::size_t length)
	{
		if (!ec)
		{
			m_pNetClientBuffer->onWriteComplete(length);

			start_async_send();
		}
		else
		{
			socket_.close();
		}
	});
}