Exemple #1
0
int Connector::DoConnect()
{
	Session * pSession = _Network->GetSessionFactory()->CreateSession(_sessionType);
	if (NULL == pSession)
	{
		return 1;//ERR_NET_CONNECTION_POOL_ALLOC_FAIL;
	}

	int rc = pSession->Create(_Network);
	if (0 != rc)
	{
		RELEASE_SESSION(pSession);
		return rc;
	}

	rc = pSession->PostConnect(this);
	if (0 != rc)
	{
		RELEASE_SESSION(pSession);
		return rc;
	}


#if !defined( __USE_CONNECTEX__ )
	rc = pSession->CompleteConnect(_sessionType);
	if (0 != rc)
	{
		Logger::Log("Session[%X] CompleteConnect Error : Err:%d\n", pSession, rc);
		pSession->Close();
		return rc;
	}
#endif

	return 0;
}
Exemple #2
0
bool_t NetworkTask::DispatchMsg()
{
	bool_t ret = FALSE;

	Buffer *buffer = network_q_->Pop();
	if(!buffer) { return FALSE; }

	Session *sess = 0;
	PacketHeader pkt_header;
	ret = buffer->GetBinary((char_t*)&pkt_header, sizeof(pkt_header));
	if(!ret) { ECILA_TRACE(); goto _ERROR; }

	//network task 는 비동기, dispatch task 는 동기이므로 세션이 먼저 close 될수 있다.
	//그러므로 활성 세션을 찻지 못했을경우는 스킵한다. 
	sess = act_sess_pool_->ACTSession(pkt_header.uidx_);
	if(!sess) { goto _ABORT; }

	if(pkt_header.cmd_ & PKT_CMD_SEND)
	{
		ret = sess->Send(buffer->GetOutPtr(), pkt_header.size_);
		if(!ret) { ECILA_TRACE(); goto _ERROR; }
	}

	if(pkt_header.cmd_ & PKT_CMD_CLOSE)
	{
		ret = sess->Close(TRUE);
		if(!ret) { ECILA_TRACE(); goto _ERROR; }
	}


_ABORT:

	ret = buff_pool_->Release(buffer);
	if(!ret) { ECILA_TRACE(); return FALSE; }

	return TRUE;



_ERROR:
	ret = buff_pool_->Release(buffer);
	if(!ret) { ECILA_TRACE(); return FALSE; }

	return FALSE;
}