コード例 #1
0
ファイル: NtlConnection.cpp プロジェクト: JunRyuu/AKCore
//-----------------------------------------------------------------------------------
//		Purpose	:
//		Return	:
//-----------------------------------------------------------------------------------
// Called by Worker TH ( CompleteRecv, CompleteAccept )
//-----------------------------------------------------------------------------------
int CNtlConnection::PostRecv()
{
	FUNCTION_BEGIN();

	if( false == IsStatus( STATUS_ACTIVE ) )
	{
		Disconnect( false );
		return NTL_SUCCESS;
		//return NTL_ERR_NET_CONNECTION_STATUS_WRONG;
	}


	DWORD dwFlags = 0;
	DWORD dwTransferedBytes	= 0;

	m_recvContext.Reset();
	m_recvContext.iomode = IOMODE_RECV;
	m_recvContext.wsabuf.buf = (char*) m_recvBuffer.GetQueuePushPtr();
	m_recvContext.wsabuf.len = m_recvBuffer.GetPushAvailableSize();


	//  [1/20/2007 zeroera] : ¼³¸í : recv buffer overflow ÀÌ°÷¿¡ °É¸®¸é ÀûÀýÇÑ ¹öÇÁ »çÀÌÁ Á¶Á¤ÇÒ °ÍÀ» °í·ÁÇÏÁö¸¸ Fake PacketÀ» º¸³»´Â Ŭ¶óÀ̾ðÆ®¸¦ ´ëºñÇÏ¿© ÀûÀýÇÑ ´ëó¸¦ ÇÒ °Í
	if( m_recvBuffer.GetPushAvailableSize() <= 0 )
	{
		Disconnect( false );

		NTL_LOGDL( LOG_NETWORK, "Session[%X] m_recvBuffer.GetPushAvailableSize() <= 0, m_recvBuffer.GetPushAvailableSize() = %d", this, m_recvBuffer.GetPushAvailableSize() );
		return NTL_ERR_NET_SESSION_RECV_BUFFER_OVERFLOW;
	}



	IncreasePostIoCount();

	int rc = m_socket.RecvEx(	&m_recvContext.wsabuf,
		1,
		&dwTransferedBytes,
		&dwFlags,
		&m_recvContext);

	if( NTL_SUCCESS != rc )
	{
		DecreasePostIoCount();

		NTL_LOGDL( LOG_NETWORK, "Session[%X] RecvEx Function Failed (%d)%s", this, rc, NtlGetErrorMessage( rc ) );
		return rc;
	}

	//NTL_PRINT( PRINT_SYSTEM, "Session[%X]\tPostRecv Complete Success recvBufferSize[%d]", this, m_recvBuffer.GetCurSize() );


	return NTL_SUCCESS;
}
コード例 #2
0
ファイル: NtlConnection.cpp プロジェクト: JunRyuu/AKCore
//-----------------------------------------------------------------------------------
//		Purpose	:
//		Return	:
//-----------------------------------------------------------------------------------
// Called by Connector TH ( Run )
//-----------------------------------------------------------------------------------
int CNtlConnection::PostConnect(CNtlConnector* pConnector)
{
	FUNCTION_BEGIN();


	if( NULL == pConnector )
	{
		return NTL_ERR_SYS_INPUT_PARAMETER_WRONG;
	}


	SetStatus( STATUS_CONNECT );


	m_pConnectorRef = pConnector;


#if !defined( __USE_CONNECTEX__ )
	int rc = m_socket.Connect( pConnector->GetConnectAddr() );
	if( NTL_SUCCESS != rc )
	{
		//NTL_LOGDL( LOG_NETWORK, "Session[%X] Connect Function Failed: (%d)%s", this, rc, NtlGetErrorMessage( rc ) );
		return rc;
	}

#else

	DWORD dwBytes = 0;

	m_recvContext.Reset();
	m_recvContext.iomode = IOMODE_CONNECT;
	m_recvContext.wsabuf.buf	= (char*) m_sendBuffer.GetQueuePushPtr();
	m_recvContext.wsabuf.len	= 0;
	IncreasePostIoCount();

	int rc = m_socket.ConnectEx(	pConnector->GetConnectAddr(),
		sizeof(struct sockaddr_in),
		m_recvContext.wsabuf.buf,
		0,
		&dwBytes,
		&m_sendContext );

	if( NTL_SUCCESS != rc )
	{
		DecreasePostIoCount();
		return rc;
	}

#endif

	return NTL_SUCCESS;
}
コード例 #3
0
ファイル: Connections.cpp プロジェクト: ChowZenki/dboserver
int Connections::PostConnect(Connector* pConnector)
{
    FUNCTION_BEGIN();


    if (NULL == pConnector)
    {
        return 1;
    }

    SetStatus(CONNSTATUS_CONNECT);

    _ConnectorRef = pConnector;


#if !defined( __USE_CONNECTEX__ )
    int rc = _socket.Connect(pConnector->GetConnectAddr());
    if (0 != rc)
    {
        return rc;
    }
#else
    DWORD Bytes = 0;

    _recvContext.Reset();
    _recvContext.iomode = IOMODE_CONNECT;
    _recvContext.wsabuf.buf = (char*)_sendBuffer.GetQueuePushPtr();
    _recvContext.wsabuf.len = 0;
    IncreasePostIoCount();

    int rc = _socket.ConnectEx(pConnector->GetConnectAddr(),
                               sizeof(struct sockaddr_in),
                               _recvContext.wsabuf.buf,
                               0,
                               &Bytes,
                               &_sendContext);

    if (0 != rc)
    {
        DecreasePostIoCount();
        return rc;
    }

#endif

    return 0;
}
コード例 #4
0
ファイル: NtlConnection.cpp プロジェクト: JunRyuu/AKCore
//-----------------------------------------------------------------------------------
//		Purpose	:
//		Return	:
//-----------------------------------------------------------------------------------
// Called by Acceptor TH ( Run )
//-----------------------------------------------------------------------------------
int CNtlConnection::PostAccept(CNtlAcceptor* pAcceptor)
{
	FUNCTION_BEGIN();

	if( NULL == pAcceptor )
	{
		return NTL_ERR_SYS_INPUT_PARAMETER_WRONG;
	}


	SetStatus( STATUS_ACCEPT );


	m_pAcceptorRef = pAcceptor;


	DWORD dwBytes = 0;

	m_recvContext.Reset();
	m_recvContext.iomode = IOMODE_ACCEPT;
	m_recvContext.wsabuf.buf = (char*) m_recvBuffer.GetQueuePushPtr();
	m_recvContext.wsabuf.len = 0;

	IncreasePostIoCount();
	m_pAcceptorRef->IncreaseCurAcceptingCount();


	int rc = pAcceptor->GetListenSocket().AcceptEx(	m_socket,
		m_recvContext.wsabuf.buf,
		0,
		sizeof(SOCKADDR_IN) + 16,
		sizeof(SOCKADDR_IN) + 16,
		&dwBytes,
		&m_recvContext );

	if( NTL_SUCCESS != rc )
	{
		DecreasePostIoCount();
		m_pAcceptorRef->DecreaseCurAcceptingCount();

		NTL_LOGDL( LOG_NETWORK, "Session[%X] AcceptEx Function Failed: (%d)%s", this, rc, NtlGetErrorMessage( rc ) );
		return rc;
	}


	return NTL_SUCCESS;
}
コード例 #5
0
ファイル: Connections.cpp プロジェクト: ChowZenki/dboserver
int Connections::PostSend()
{
    FUNCTION_BEGIN();

    if (false == IsStatus(CONNSTATUS_ACTIVE))
    {
        Disconnect(false);
        return 0;
    }


    DWORD Flags = 0;
    DWORD SendBytes = 0;

    _sendContext.Reset();
    _sendContext.iomode = IOMODE_SEND;
    _sendContext.wsabuf.buf = (char*)_sendBuffer.GetQueuePopPtr();

    if (_sendBuffer.GetPopPos() + _sendBuffer.GetCurSize() >= _sendBuffer.GetQueueSize())
    {
        _sendContext.wsabuf.len = _sendBuffer.GetQueueSize() - _sendBuffer.GetPopPos();
    }
    else
    {
        _sendContext.wsabuf.len = _sendBuffer.GetCurSize();
    }

    IncreasePostIoCount();

    int rc = _socket.SendEx(&_sendContext.wsabuf,
                            1,
                            &SendBytes,
                            Flags,
                            &_sendContext);

    if (0 != rc)
    {
        DecreasePostIoCount();
        Logger::Log("Session[%X] SendEx Function Failed: (%d)\n", this, rc);
        return rc;
    }

    return 0;
}
コード例 #6
0
ファイル: Connections.cpp プロジェクト: ChowZenki/dboserver
int Connections::PostAccept(Acceptor* pAcceptor)
{
    FUNCTION_BEGIN();

    if (NULL == pAcceptor)
    {
        return 1;
    }

    SetStatus(CONNSTATUS_ACCEPT);

    _AcceptorRef = pAcceptor;

    DWORD Bytes = 0;

    _recvContext.Reset();
    _recvContext.iomode = IOMODE_ACCEPT;
    _recvContext.wsabuf.buf = (char*)_recvBuffer.GetQueuePushPtr();
    _recvContext.wsabuf.len = 0;

    IncreasePostIoCount();
    _AcceptorRef->IncreaseCurAcceptingCount();


    int rc = pAcceptor->GetListenSocket().AcceptEx(_socket,
             _recvContext.wsabuf.buf,
             0,
             sizeof(SOCKADDR_IN) + 16,
             sizeof(SOCKADDR_IN) + 16,
             &Bytes,
             &_recvContext);

    if (0 != rc)
    {
        DecreasePostIoCount();
        _AcceptorRef->DecreaseCurAcceptingCount();
        Logger::Log("Session[%X] AcceptEx Function Failed: (%d)\n", this, rc);
        return rc;
    }

    return 0;
}
コード例 #7
0
ファイル: Connections.cpp プロジェクト: ChowZenki/dboserver
int Connections::PostRecv()
{
    FUNCTION_BEGIN();

    if (false == IsStatus(CONNSTATUS_ACTIVE))
    {
        Disconnect(false);
        return 0;
    }

    DWORD Flags = 0;
    DWORD TransferedBytes = 0;

    _recvContext.Reset();
    _recvContext.iomode = IOMODE_RECV;
    _recvContext.wsabuf.buf = (char*)_recvBuffer.GetQueuePushPtr();
    _recvContext.wsabuf.len = _recvBuffer.GetPushAvailableSize();

    if (_recvBuffer.GetPushAvailableSize() <= 0)
    {
        Disconnect(false);
        Logger::Log("Session[%X] _recvBuffer.GetPushAvailableSize() <= 0, _recvBuffer.GetPushAvailableSize() = %d\n", this, _recvBuffer.GetPushAvailableSize());
        return -1; //ERR_NET_SESSION_RECV_BUFFER_OVERFLOW
    }

    IncreasePostIoCount();

    int rc = _socket.RecvEx(&_recvContext.wsabuf,
                            1,
                            &TransferedBytes,
                            &Flags,
                            &_recvContext);

    if (0 != rc)
    {
        DecreasePostIoCount();
        Logger::Log("Session[%X] RecvEx Function Failed (%d)/n", this, rc);
        return rc;
    }

    return 0;
}
コード例 #8
0
ファイル: NtlConnection.cpp プロジェクト: JunRyuu/AKCore
//-----------------------------------------------------------------------------------
//		Purpose	:
//		Return	:
//-----------------------------------------------------------------------------------
// Called by App TH, Worker TH ( CompleteSend, PushPacket )
//-----------------------------------------------------------------------------------
int CNtlConnection::PostSend()
{
	FUNCTION_BEGIN();

	if( false == IsStatus( STATUS_ACTIVE ) )
	{
		Disconnect( false );
		return NTL_SUCCESS;
		//return NTL_ERR_NET_CONNECTION_STATUS_WRONG;
	}


	DWORD dwFlags		= 0;
	DWORD dwSendBytes	= 0;

	m_sendContext.Reset();
	m_sendContext.iomode = IOMODE_SEND;
	m_sendContext.wsabuf.buf = (char*) m_sendBuffer.GetQueuePopPtr();

#if __SGPRO_BOTSYSTEM_SENDANDRECVTESTCODE__
	bool bIsIf = false;
#endif

	if( m_sendBuffer.GetPopPos() + m_sendBuffer.GetCurSize() >= m_sendBuffer.GetQueueSize() )
	{

#if __SGPRO_BOTSYSTEM_SENDANDRECVTESTCODE__
		bIsIf = true;
#endif

		//  [9/13/2007 zeroera] : ¼öÁ¤ : ¼º´É °³¼±À» À§ÇØ ¼öÁ¤ÇÒ ºÎºÐ
		m_sendContext.wsabuf.len = m_sendBuffer.GetQueueSize() - m_sendBuffer.GetPopPos();

		//if( m_sendBuffer.GetQueueSize() <= m_sendBuffer.GetPopPos() )
		//{
		//	NTL_LOG_ASSERT("m_sendBuffer.GetQueueSize() <= m_sendBuffer.GetPopPos(), m_sendBuffer.GetQueueSize() = %d, m_sendBuffer.GetPopPos() = %d", m_sendBuffer.GetQueueSize(), m_sendBuffer.GetPopPos());
		//	Disconnect( false );
		//	return NTL_SUCCESS;
		//}
	}
	else
	{
		m_sendContext.wsabuf.len = m_sendBuffer.GetCurSize();

		//if( m_sendBuffer.GetCurSize() <= 0 )
		//{
		//	NTL_LOG_ASSERT("m_sendBuffer.GetCurSize() <= 0, m_sendBuffer.GetCurSize() = %d", m_sendBuffer.GetCurSize());
		//	Disconnect( false );
		//	return NTL_SUCCESS;
		//}
	}


	IncreasePostIoCount();

	int rc = m_socket.SendEx(	&m_sendContext.wsabuf,
							 1,
							 &dwSendBytes,
							 dwFlags,
							 &m_sendContext);

	if( NTL_SUCCESS != rc )
	{
		DecreasePostIoCount();

		NTL_LOGDL( LOG_NETWORK, "Session[%X] SendEx Function Failed: (%d)%s", this, rc, NtlGetErrorMessage( rc ) );
		return rc;
	}

#if __SGPRO_BOTSYSTEM_SENDANDRECVTESTCODE__
	m_cConsolLog.WriteBotSystemLog( reinterpret_cast< void * >( m_sendContext.wsabuf.buf )
		, m_sendContext.wsabuf.len
		, bIsIf 
		, &m_sendBuffer
		, m_nCharacterPCID);
#endif//__SGPRO_BOTSYSTEM_SENDANDRECVTESTCODE__

	//NTL_PRINT( PRINT_SYSTEM, "Session[%X]\tPostSend Complete SendBufferSize[%d]", this, m_sendBuffer.GetCurSize() );

	return NTL_SUCCESS;
}