#include "stdafx.h" #include "./ChildServerSession.h" #include #include #include #include "QueryObjects/QueryPoolFactory.h" #include "DBProxyServerEx.h" #include "DBUserManager.h" #include "QueryObjects/DBHandler.h" #include "QueryObjects/DBUnit.h" //================================================================================================== ChildServerSession::ChildServerSession() : db_unit_id_(0) , sync_key_(0) { // ¼¼¼Ç Ç®À» ¼³Á¤ÇÒ ¶§¸¸ ¼öÇàµÈ´Ù. workload_packet_stream_.Initialize(WorkLoadPacketStream::c_DefaultUpdateTick, WorkLoadPacketStream::c_DefaultLimitTransferSize); workload_.Initialize(); } ChildServerSession::~ChildServerSession() { // ¾Æ¸¶ ¼¼¼Ç Ç®À» ÇØÁ¦ÇÒ °æ¿ì¸¸ ¼öÇàµÉ µí. workload_packet_stream_.Initialize(WorkLoadPacketStream::c_DefaultUpdateTick, WorkLoadPacketStream::c_DefaultLimitTransferSize); workload_.Release(true); } void ChildServerSession::Init() { ServerSession::Init(); SetSyncKey(TEMP_SERVER); } void ChildServerSession::Release() { ServerSession::Release(); SetSyncKey(TEMP_SERVER); } void ChildServerSession::OnDisconnect() { ServerSession::OnDisconnect(); g_DBHandler.DeallocateDBUnit(db_unit_id_); db_unit_id_ = 0; SetSyncKey(TEMP_SERVER); workload_packet_stream_.Initialize(WorkLoadPacketStream::c_DefaultUpdateTick, WorkLoadPacketStream::c_DefaultLimitTransferSize); // À̰ÍÀº ¸ðµç WorkµéÀ» Á¦°ÅÇÏ´Â °ÍÀ̹ǷΠ¿Ã¹Ù¸¥ À§Ä¡¿¡ »ç¿ëµÇÁö ¾ÊÀº °ÍÀÌ´Ù. //WorkLoadManager::ReleaseTaskAll(); workload_.Release(true); } #if SUN_CODE_BACKUP // NOTE: f110617.1L, don't called by root, use OnRedirect event. void ChildServerSession::OnAccept(DWORD index) { ServerSession::OnAccept(index); SUNLOG(eCRITICAL_LOG, _T("[OnAccept][%u] Server Accept(%s)"), index, GetServerType2String(GetServerType())); } #endif void ChildServerSession::OnRedirect(DWORD network_index, MSG_SERVER_TYPE* const first_contact_msg) { ServerSession::OnRedirect(network_index, first_contact_msg); db_unit_id_ = g_DBHandler.AllocateDBUnit(GetServerType(), GetSessionIndex()); ASSERT(0 != db_unit_id_); DBUnit* db_unit = g_DBHandler.FindDBUnit(db_unit_id_); ASSERT(db_unit); if(!db_unit) { SUNLOG(eCRITICAL_LOG, _T("[%u:%s:%s] Can't allocate DB connection"), network_index, GetServerType2String(GetServerType()), this->GetConnectIP().c_str()); NetworkObject::Disconnect(true); return; } ASSERT(g_DBHandler.FindDBUnit(db_unit_id_)->GetSessionIndex() == GetSessionIndex()); SUNLOG(eCRITICAL_LOG, "[Redirect][%u] Server Redirect(%s)", GetSessionIndex(), GetServerType2String(GetServerType())); } void ChildServerSession::DBQuery(BYTE category, BYTE protocol, Query* query) { query->SetIndex(MAKEDWORD((WORD)category, (WORD)protocol)); query->SetVoidObject(this); g_DBHandler.DBQuery(db_unit_id_, query); } void ChildServerSession::DBQuery(Query* query) { query->SetVoidObject(this); g_DBHandler.DBQuery(db_unit_id_, query); } BOOL ChildServerSession::IsValidObject(DWORD check_value) { return sync_key_ == check_value; } BOOL ChildServerSession::IsValidState(DWORD status_value) { DWORD status = (DWORD)g_DBProxyServer.GetPhaseStatus(); return status == status_value; } BOOL ChildServerSession::SendPacket4Interface(MSG_BASE* pMsg, WORD wSize) { return SendPacket(pMsg, wSize); }