// decrement the player count advertised on this session // DWORD XBL_MM_RemovePlayer( bool usePrivateSlot ) { if(!logged_on || !session.Exists()) return -1; // The value we're given only tells us if they were eligble for a private slot when // they joined, but they may have actually ended up in a public slot. As such, this // can get pretty wacky. Oh well. if ( usePrivateSlot && session.PrivateFilled ) { session.PrivateFilled--; session.PrivateOpen++; session.TotalPlayers--; } else { if ( session.PublicFilled ) { session.PublicFilled--; session.PublicOpen++; session.TotalPlayers--; } else { assert( 0 ); } } session.Update(); return 0; }
void CWorkThreadEvent::workThreadEventCB(struct bufferevent *bev, short event, void *arg) { CSessionManager *pSessionManager = (CSessionManager *)arg; CSession *pSession = pSessionManager->getSession(bev); if (NULL == pSession) { bufferevent_free(bev); return; } pSessionManager->setCurSession(pSession); pSessionManager->getInterface()->onSocketClose(); pSessionManager->setCurSession(NULL); if (pSession->getServerLinker()) { CServerLinker *pServerLinker = (CServerLinker *)pSession->getHandle(); if (NULL != pServerLinker) { pSessionManager->delServerLinker(pServerLinker->getLinkerName()); pServerLinker->setLinked(false); } } pSessionManager->dellSession(bev); bufferevent_free(bev); }
int CMain::SessionTimeOutHandler() { int nRet = 0; time_t curTm = 0; CSession *cSession = NULL; curTm = time(NULL); while(m_lstSession.size()){ cSession = m_lstSession.front(); if((curTm - cSession->GetSendTime()) <= m_nTimeOut){ return CLA_OK; } CLA_LOG(CLA_ERR,false,"Session timeout(curTm=%lu, sendTime=%lu, diff=%lu sessionId=%d, timeOut=%d)\n", curTm, cSession->GetSendTime(), (curTm - cSession->GetSendTime()), cSession->GetSessionId(), m_nTimeOut); nRet = UpdateHistErr(cSession, CLA_RSLT_CODE_TIME_OUT); if(nRet != CLA_OK){ CLA_LOG(CLA_ERR,false,"Command history update failed(nRet=%d)\n",nRet); } delete cSession; m_lstSession.pop_front(); } return CLA_OK; }
void CWorkThreadEvent::addServerLinker(struct event_base *pMainBase, CSessionManager *pSessionManager, OrderMsg &stOrderMsg) { struct bufferevent *pBev = NULL; CSession *pSession = NULL; CServerLinker *pServerLinker = (CServerLinker *)stOrderMsg.pHandle; if (NULL == pServerLinker) { Q_Printf("%s", Q_EXCEPTION_NULLPOINTER); return; } if (Q_INVALID_SOCK == pServerLinker->getSock()) { Q_Printf("%s", "invalid socket"); return; } (void)evutil_make_socket_nonblocking(pServerLinker->getSock()); pBev = bufferevent_socket_new(pMainBase, pServerLinker->getSock(), BEV_OPT_CLOSE_ON_FREE); if (NULL == pBev) { Q_Printf("%s", "bufferevent_socket_new error."); return; } if (Q_RTN_OK != pSessionManager->addSession(pBev)) { bufferevent_free(pBev); Q_Printf("%s", "add session error."); return; } bufferevent_setcb(pBev, workThreadReadCB, NULL, workThreadEventCB, pSessionManager); if (Q_RTN_OK != bufferevent_enable(pBev, EV_READ | EV_WRITE)) { pSessionManager->dellSession(pBev); bufferevent_free(pBev); pBev = NULL; Q_Printf("%s", "bufferevent_enable error."); return; } pSessionManager->addServerLinker(pServerLinker->getLinkerName(), pBev); pSession = pSessionManager->getSession(pBev); pSession->setHandle(pServerLinker); pSession->setServerLinker(true); pServerLinker->setLinked(true); pSessionManager->getInterface()->onLinkedServer(pSession); }
//##ModelId=41DDF2410119 CSession* CSessionFactory::CreateSession(DWORD dwLifeTime, SESSION_TYPE st ) { // TODO: Add your specialized code here. // NOTE: Requires a correct return value to compile. CSession* pSession = NULL; switch( st ) { case ST_WS_SESSION: { pSession = new CWorldServerSession( dwLifeTime ); } break; //case ST_TEAM: // { // pSession = new CTeam( dwMinPlugs, dwMaxPlugs, dwLifeTime ); // } //break; } if( pSession ) { CGUID guid; CGUID::CreateGUID(guid); pSession->SetSessionType( st ); pSession->SetExID( guid ); s_mSessions[pSession->GetExID()] = pSession; } return pSession; }
unsigned long __stdcall ClientThread(void* pVoid) { CSession *session = (CSession*)pVoid; log(LOG_DEBUG, "DEBUG - client thread started for session S%d - ClientThread()\r\n", session->m_SessionIndex); // Send Welcome Message send(session->getMainSock(), MSG_CONNECTED_1, lstrlen(MSG_CONNECTED_1), 0); send(session->getMainSock(), VERSION, lstrlen(VERSION), 0); send(session->getMainSock(), MSG_CONNECTED_2, lstrlen(MSG_CONNECTED_2), 0); // Dialog with FTP client session->dialog(); // Object is deleted by Ftpd object // wait for session to be closed while (!session->m_IsClosed) { Sleep(200); } // unregister session (session->getCFtpd())->removeSession(session->m_SessionIndex); return 0; }
// increment the player count advertised on this session // DWORD XBL_MM_AddPlayer( bool usePrivateSlot ) { if (!logged_on || !session.Exists()) return -1; // SOF2 had a really bad system that checked for server's friends. We do what // MS says is good - all invites/joins go into private, everyone else goes public. if( usePrivateSlot && session.PrivateOpen ) { session.PrivateFilled++; session.PrivateOpen--; session.TotalPlayers++; } else { // Either joined via matchmaking, or we don't have any more private slots // Give them a public slot. if ( session.PublicOpen ) { session.PublicFilled++; session.PublicOpen--; session.TotalPlayers++; } else { assert( 0 ); } } session.Update(); return 0; }
void LimitMappingScripwise::getSymbolData() { HRESULT hr; CoInitialize(NULL); CDataSource connection; CSession session; CCommand<CAccessor<CTrade_Table> > artists1; connection.OpenFromInitializationString(L"Provider=SQLNCLI11.1;Password=ok@12345;Persist Security Info=False;User ID=sa;Initial Catalog=TradeDataBase;Data Source=68.168.101.187;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=WINDOWS-LOJSHQK;Initial File Name=\"\";Use Encryption for Data=False;Tag with column collation when possible=False;MARS Connection=False;DataTypeCompatibility=0;Trust Server Certificate=False;Application Intent=READWRITE"); session.Open(connection); _bstr_t strCommand=""; CString sel_login=GridTradeAndOrder::m_selected_login; sel_login=sel_login.Mid(0,6); _bstr_t strcode=sel_login; //select distinct symbol,0 as 'Limit','' as 'Client_group','' as 'Client_Group1','' as 'Client_Group2','' as 'v','' as 'ba','' as 'TYPE','' as 'volume' ,'' AS 'cHECKtRADE' from mt5_deals where [Action] in (0,1) and symbol not in (select Symbol from Limit_Mapping where [login]='" + GridTradeAndOrder::m_selected_login + "' )union select Symbol,Limit from Limit_Mapping where [login]='" + GridTradeAndOrder::m_selected_login + "' " strCommand="select distinct symbol,0 as 'LimitBuy',0 as 'Client_group','' as 'Client_Group1','' as 'Client_Group2','' as 'v','' as 'ba','' as 'TYPE','' as 'volume' ,'' AS 'cHECKtRADE' from mt5_deals where [Action] in (0,1) and symbol not in (select Symbol from Limit_Mapping where [login]='" + GridTradeAndOrder::m_selected_login + "' )union select Symbol,Limit,LimitSell as 'Client_group','' as 'Client_Group1','' as 'Client_Group2','' as 'v','' as 'ba','' as 'TYPE','' as 'volume' ,'' AS 'cHECKtRADE' from Limit_Mapping where [login]='" + GridTradeAndOrder::m_selected_login + "' "; char* strCommand_char=(char*)strCommand; hr=artists1.Open(session,strCommand_char); int rows_count=0; if(SUCCEEDED(hr)) { while (artists1.MoveNext() == S_OK) { e_grid.QuickSetText(0,rows_count,artists1.m_Symbol ); e_grid.QuickSetText(1,rows_count,artists1.m_Order); e_grid.QuickSetText(2,rows_count,artists1. m_Time); rows_count=rows_count+1; } } artists1.Close(); session.Close(); connection.Close(); }
//! acceptµ½client bool CServerNetworkImp::OnAccept(ITcpSocket * s) { CSession * p = new CSession; s->Initialize(m_ios, p); p->InitSocketForServer(this, s,++m_nCurMaxConnectID); g_nTotalLinked ++; return true; }
UINT Show_NPBPStype1(void *pParam) { CNPBPSType1Grid* pThis= (CNPBPSType1Grid*)pParam; CoInitialize(NULL); CDataSource connection; CSession session; CCommand<CAccessor<NPBPSType1Table> > artists1; HRESULT hr; hr=connection.OpenFromInitializationString(L"Provider=SQLNCLI11.1;Password=ok@12345;Persist Security Info=False;User ID=sa;Initial Catalog=Tradedatabase;Data Source=68.168.101.187;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=WINDOWS-LOJSHQK;Initial File Name=\"\";Use Encryption for Data=False;Tag with column collation when possible=False;MARS Connection=False;DataTypeCompatibility=0;Trust Server Certificate=False;Application Intent=READWRITE"); if(SUCCEEDED(hr)) { hr=session.Open(connection); while (true ) { CString strCommand=L""; strCommand.Format(L"proc_Type2"); _bstr_t bstrCommand=""; bstrCommand=strCommand; char* strCommand_char=(char*)bstrCommand; if(SUCCEEDED(hr)) { hr=artists1.Open(session,strCommand_char); } CNPBPSType1Grid::dealing_mutex.Lock(); if(SUCCEEDED(hr)) { CNPBPSType1Grid::m_st_Dealing_Array.Clear(); CNPBPSType1Grid::st_Dealing m_st_Dealing={}; while (artists1.MoveNext() == S_OK) { CMTStr::Copy(m_st_Dealing.Section ,artists1.m_Section ); CMTStr::Copy(m_st_Dealing.Login ,artists1.m_login ); m_st_Dealing.Order =artists1.m_Order; CMTStr::Copy(m_st_Dealing.Order_In_Time,artists1.m_Order_In_Time ) ; m_st_Dealing.Deal=artists1.m_Deal ; CMTStr::Copy(m_st_Dealing.Symbol ,artists1.m_Symbol ); CMTStr::Copy(m_st_Dealing.Type1 ,artists1.m_Type1 ); m_st_Dealing.Volume =artists1.m_Volume ; m_st_Dealing.Price =artists1.m_Price; CMTStr::Copy(m_st_Dealing.Comment,artists1.m_Comment); CMTStr::Copy(m_st_Dealing.Status,artists1.m_Status); CMTStr::Copy(m_st_Dealing.Type,artists1.m_Type); CMTStr::Copy(m_st_Dealing.SubType,artists1.m_SubType); CNPBPSType1Grid::m_st_Dealing_Array.Add(&m_st_Dealing); } artists1.Close(); } CNPBPSType1Grid::dealing_mutex.Unlock(); Sleep(1000); } } return 0; }
int main(int argc, char **argv) { CEventManager::instance(); CSDLManager::instance(); CClock::instance(); CSession *session = new CSession(); session->run(); return 0; }
/* static */ bool UIMachine::startMachine(const QString &strID) { /* Some restrictions: */ AssertMsgReturn(vboxGlobal().isValid(), ("VBoxGlobal is invalid.."), false); AssertMsgReturn(!vboxGlobal().virtualMachine(), ("Machine already started.."), false); /* Restore current snapshot if requested: */ if (vboxGlobal().shouldRestoreCurrentSnapshot()) { /* Create temporary session: */ CSession session = vboxGlobal().openSession(strID, KLockType_VM); if (session.isNull()) return false; /* Which VM we operate on? */ CMachine machine = session.GetMachine(); /* Which snapshot we are restoring? */ CSnapshot snapshot = machine.GetCurrentSnapshot(); /* Prepare restore-snapshot progress: */ CProgress progress = machine.RestoreSnapshot(snapshot); if (!machine.isOk()) return msgCenter().cannotRestoreSnapshot(machine, snapshot.GetName(), machine.GetName()); /* Show the snapshot-discarding progress: */ msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_snapshot_discard_90px.png"); if (progress.GetResultCode() != 0) return msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName(), machine.GetName()); /* Unlock session finally: */ session.UnlockMachine(); /* Clear snapshot-restoring request: */ vboxGlobal().setShouldRestoreCurrentSnapshot(false); } /* For separate process we should launch VM before UI: */ if (vboxGlobal().isSeparateProcess()) { /* Get corresponding machine: */ CMachine machine = vboxGlobal().virtualBox().FindMachine(vboxGlobal().managedVMUuid()); AssertMsgReturn(!machine.isNull(), ("VBoxGlobal::managedVMUuid() should have filter that case before!\n"), false); /* Try to launch corresponding machine: */ if (!vboxGlobal().launchMachine(machine, VBoxGlobal::LaunchMode_Separate)) return false; } /* Try to create machine UI: */ return create(); }
unsigned long __stdcall PasvThread(void* pVoid) { CSession *session = (CSession*)pVoid; sockaddr_in remoteAddr_in; int nLen; session->m_PasvThreadRunning = true; log(LOG_DEBUG, "DEBUG - passive thread was started, waiting for incoming connection - PasvThread()\r\n"); nLen = sizeof(sockaddr_in); // Accept incoming connections on passive port SOCKET s = accept(session->getPasvSock(), (sockaddr *)&remoteAddr_in, &nLen); if (s != INVALID_SOCKET) { log(LOG_DEBUG, "DEBUG - passive thread received a connection (socket %d) - PasvThread()\r\n", s); if (session->getPasvSock2()!=0) { session->closePasvSock2(); } session->setPasvSock2(s); // session->m_PasvPort = -1; // log(LOG_DEBUG, "Passive port free.\r\n"); } session->closePasvSock(); session->getCFtpd()->freePasvPort(session->getPasvPort()); log(LOG_DEBUG, "DEBUG - passive thread was stopped - PasvThread()\r\n"); session->m_PasvThreadRunning = false; return 0; }
void VBoxSnapshotsWgt::sltRestoreSnapshot(bool fSuppressNonCriticalWarnings /* = false*/) { /* Get currently chosen item: */ SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast<SnapshotWgtItem*>(mTreeWidget->currentItem()) : 0; AssertReturn(pItem, (void)0); /* Detemine snapshot id: */ QString strSnapshotId = pItem->snapshotId(); AssertReturn(!strSnapshotId.isNull(), (void)0); /* Get currently desired snapshot: */ CSnapshot snapshot = mMachine.FindSnapshot(strSnapshotId); /* Ask the user if he really wants to restore the snapshot: */ int iResultCode = AlertButton_Ok; if (!fSuppressNonCriticalWarnings || mMachine.GetCurrentStateModified()) { iResultCode = msgCenter().confirmSnapshotRestoring(snapshot.GetName(), mMachine.GetCurrentStateModified()); if (iResultCode & AlertButton_Cancel) return; } /* If user also confirmed new snapshot creation: */ if (iResultCode & AlertOption_CheckBox) { /* Take snapshot of changed current state: */ mTreeWidget->setCurrentItem(curStateItem()); if (!takeSnapshot()) return; } /* Open a direct session (this call will handle all errors): */ CSession session = vboxGlobal().openSession(mMachineId); if (session.isNull()) return; /* Restore chosen snapshot: */ CConsole console = session.GetConsole(); CProgress progress = console.RestoreSnapshot(snapshot); if (console.isOk()) { msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_restore_90px.png"); if (progress.GetResultCode() != 0) msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName(), mMachine.GetName()); } else msgCenter().cannotRestoreSnapshot(console, snapshot.GetName(), mMachine.GetName()); /* Unlock machine finally: */ session.UnlockMachine(); }
void VBoxSnapshotDetailsDlg::putBackToSnapshot() { AssertReturn (!mSnapshot.isNull(), (void) 0); /* We need a session when we manipulate the snapshot data of a machine. */ CSession session = vboxGlobal().openExistingSession(mSnapshot.GetMachine().GetId()); if (session.isNull()) return; mSnapshot.SetName(mLeName->text()); mSnapshot.SetDescription(mTeDescription->toPlainText()); /* Close the session again. */ session.UnlockMachine(); }
// Finish off and tidy up match making void XBL_MM_Shutdown( bool processLogon ) { // We're killing our session, no matter what session.Delete(); // XDK code to finish this off, while not letting the logon task expire, // except if we're already leaving live, where we can get into a recursive // com_error situation: HRESULT hr; do { if( processLogon && !XBL_PumpLogon() ) return; hr = session.Process(); } while ( session.IsDeleting() ); }
void VBoxSnapshotsWgt::sltDeleteSnapshot() { SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 : static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem()); AssertReturn (item, (void) 0); QString snapId = item->snapshotId(); AssertReturn (!snapId.isNull(), (void) 0); CSnapshot snapshot = mMachine.FindSnapshot(snapId); if (!msgCenter().confirmSnapshotRemoval(snapshot.GetName())) return; /** @todo check available space on the target filesystem etc etc. */ #if 0 if (!msgCenter().warnAboutSnapshotRemovalFreeSpace(snapshot.GetName(), "/home/juser/.VirtualBox/Machines/SampleVM/Snapshots/{01020304-0102-0102-0102-010203040506}.vdi", "59 GiB", "15 GiB")) return; #endif /* Open a direct session (this call will handle all errors) */ bool busy = mSessionState != KSessionState_Unlocked; CSession session; if (busy) session = vboxGlobal().openExistingSession(mMachineId); else session = vboxGlobal().openSession(mMachineId); if (session.isNull()) return; CConsole console = session.GetConsole(); CProgress progress = console.DeleteSnapshot (snapId); if (console.isOk()) { /* Show the progress dialog */ msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_discard_90px.png"); if (progress.GetResultCode() != 0) msgCenter().cannotRemoveSnapshot(progress, snapshot.GetName(), mMachine.GetName()); } else msgCenter().cannotRemoveSnapshot(console, snapshot.GetName(), mMachine.GetName()); session.UnlockMachine(); }
int HandleTimeout( void ) { CSession* lpoSession = NULL; if (GetCycle()->GetSessionManager()->Find(lpoSession, "127.0.0.1", 4001)) { CAny loRequest(&moBlock); lpoSession->Write(loRequest); printf("HAHA Test.\n"); } else { printf("HAHA Test failure.\n"); } GetCycle()->GetTimer()->Add(this, 100 * 1000); return 0; }
/** @brief From CertifyServer 인증서버로 부터 받는다. ReqLogin -> ReqUserLogin -> AckUserLogin */ bool CBasicC2SHandler_LoginSvr::AckUserLogin(certify::AckUserLogin_Packet &packet) { CSession *pClient = network::CheckClientId( &GetServer(), packet.id, 0, &m_BasicProtocol, packet.pdispatcher ); RETV(!pClient, false); if (packet.errorCode != error::ERR_SUCCESS) { clog::Error( clog::ERROR_PROBLEM, "AckUserId Error!! client generate user id Error id=%s", packet.id.c_str()); m_BasicProtocol.AckLogIn(pClient->GetNetId(), SEND_T, packet.errorCode, packet.id, 0); return false; } pClient->SetState(SESSIONSTATE_LOGIN); // login state pClient->SetCertifyKey( packet.c_key ); m_BasicProtocol.AckLogIn(pClient->GetNetId(), SEND_T, packet.errorCode, packet.id, packet.c_key ); return true; }
CSession* CMain::FindSession(unsigned int a_nSessionId) { CSession *cSession = NULL; list<CSession*>::iterator iter; for(iter = m_lstSession.begin();iter != m_lstSession.end(); iter++){ cSession = *iter; if(cSession->GetSessionId() == a_nSessionId){ m_lstSession.erase(iter); return cSession; } } return NULL; }
/* static */ bool UIVMItem::isItemRunningHeadless(UIVMItem *pItem) { if (isItemRunning(pItem)) { /* Open session to determine which frontend VM is started with: */ CSession session = vboxGlobal().openExistingSession(pItem->id()); if (!session.isNull()) { /* Acquire the session name: */ const QString strSessionName = session.GetMachine().GetSessionName(); /* Close the session early: */ session.UnlockMachine(); /* Check whether we are in 'headless' session: */ return strSessionName == "headless"; } } return false; }
void Do( DWORD dwTimeout = -1 ){ char buf[] = "GET /www.yoheim.net/?key1=value1&key2=value2 HTTP/1.1\n" "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" "Accept-Charset:Shift_JIS,utf-8;q=0.7,*;q=0.3" "Accept-Encoding:gzip,deflate,sdch" "Accept-Language:ja,en-US;q=0.8,en;q=0.6" "Cache-Control:max-age=0" "Connection:keep-alive" "Cookie:utma=something;" "Host:www.yoheim.net" "User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.54 Safari/536.5\n\n" "key1=value1&key2=value2\n" ; UINT id = 123; CSession* pSession = CSessionManager::Instance().Find( id ); if( pSession ) { pSession->OnRecv( new CBuffer((BYTE*)buf,strlen(buf)+1) ); } }
unsigned long __stdcall ListenThread(void *pVoid) { sockaddr_in remoteAddr_in; int nLen; CFtpd *ftp; ftp = (CFtpd*)pVoid; nLen = sizeof(sockaddr_in); while(!ftp->m_ShouldStop) { DWORD nThreadID; SOCKET s = accept(ftp->getListeningSock(), (sockaddr *)&remoteAddr_in, &nLen); if (s != INVALID_SOCKET && !ftp->m_ShouldStop) { log(LOG_DEBUG, "DEBUG - main listening thread accepted a connection from %s - ListenThread()\r\n", inet_ntoa(remoteAddr_in.sin_addr)); // Create a new CSession CSession *session; session = new CSession(s, ftp); session->setClientAddr ((in_addr)(remoteAddr_in.sin_addr)); // Start a client thread to handle this request HANDLE h = CreateThread(0, 0, ClientThread, (void*)session, 0, &nThreadID); // SetThreadPriority(h, THREAD_PRIORITY_LOWEST); // Set Session's thread handle session->setMainThread(h); // Register Cftpd's session session->m_SessionIndex = ftp->addSession(session); } } return 0; }
void CWorkThreadEvent::workThreadReadCB(struct bufferevent *bev, void *arg) { char *pTmp = NULL; Q_PackHeadType packLens = Q_INIT_NUMBER; CSessionManager *pSessionManager = (CSessionManager *)arg; CSession *pSession = pSessionManager->getSession(bev); if (NULL == pSession) { Q_Printf("%s", "get session error."); bufferevent_free(bev); return; } pSessionManager->setCurSession(pSession); while(NULL != (pTmp = getDataPack(pSession, packLens))) { pSessionManager->getInterface()->onSocketRead(pTmp, packLens); (void)pSession->getBuffer()->delBuffer(packLens + sizeof(packLens)); } pSessionManager->setCurSession(NULL); }
CSession* CSessionManager::addSession(string strSessionName, vector<string>& vecPaths) { uint32 uiSessionIndex = getEntryCount() + 1; CSession *pSession = new CSession; pSession->m_strName = strSessionName; pSession->m_vecPaths = vecPaths; addEntry(pSession); CRegistryManager::setSoftwareValueInt("IMGF\\Sessions", "Count", uiSessionIndex); CRegistryManager::setSoftwareValueString("IMGF\\Sessions", "Data_" + CString2::toString(uiSessionIndex), pSession->serialize()); return pSession; }
void* Connector::threadRoutine(void *args) { if (false) { return NULL; } while (true) { if (sem_wait(&m_waitSem) < 0) { perror("sem_wait error"); assert(false); } pthread_mutex_lock(&m_mutex); while(!m_waitList.empty()) { CSession *pSession = m_waitList.front(); m_waitList.pop_front(); Int32 connResult = ::connect(pSession->getSocket(), (struct sockaddr*)(&(pSession->getSockAddr())), sizeof(struct sockaddr_in)); cout << "connect thread=======ip:" << pSession->getIp() << " port:" << pSession->getPort() << endl; if(connResult<0) { printf("connect error\n"); m_connErrListLock.lock(); m_connErrList.push_back(pSession); m_connErrListLock.unLock(); } else { printf("connect success:%s\n", pSession->getIp()); Int32 ioFlag; ioFlag = fcntl(pSession->getSocket(), F_GETFL); fcntl(pSession->getSocket(), F_SETFL, ioFlag|O_NONBLOCK); //set nonblock socket m_connListLock.lock(); m_connList.push_back(pSession); m_connListLock.unLock(); } } pthread_mutex_unlock(&m_mutex); } return NULL; }
// Ensure that our session is being advertised correctly // Will update map name after a level change, etc... void XBL_MM_Advertise() { // If not on xboxlive dont post server if(!logged_on) return; if ( session.Exists() ) { // Our session is already being advertised, update it XBL_MM_Update_Session(); } else { // Brand new session XBL_MM_Init_Session(); } }
// run this code every game tick // will only be called while logged on // void XBL_MM_Tick() { // VVFIXME - SOF2 re-advertised after some crazy timeout. // New version just ticks the session object as well, it does nothing if it's not real HRESULT hr = session.Process(); #ifdef _DEBUG if ( FAILED( hr ) ) Com_Printf("session.Process() failed: %s\n", getXBLErrorName(hr)); #endif // The only time we need to do async work on the query is when probing for QoS if ( query.IsProbing() ) { query.Process(); } }
bool Connector::connect(const char *szIp, Int32 Port, uint8 serverid) { CSession *pSession = m_sessionFactory.allocate(); if (NULL == pSession) { printf("connector can not alloc Session\n"); return false; } pSession->setType(SIDGenerator::getInstance()->getServerTypeBySvrID(serverid)); pSession->setConnectSvrID(serverid); pSession->setIsFromSelf(true);//means this connection is create from server itself pSession->setServer(m_ptrServer); Int32 cliSock = socket(AF_INET, SOCK_STREAM, 0); if (cliSock < 0) { printf("connector create sock error\n"); return false; } struct sockaddr_in addr; bzero(&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(szIp); addr.sin_port = htons(Port); pSession->setSocket(cliSock); pSession->setSockAddr(addr); pSession->setIp(szIp); pSession->setPort(Port); addToWaitList(pSession); return true; }
void XBL_MM_Update_Session() { // VVFIXME - Do we need to ensure that slot counts are right? // Our gamertag hasn't changed (I hope) so we leave that alone. // Get current map index, and gametype int index = mapNameToIndex( sv_mapname->string ); if (index == MAP_ARRAY_SIZE) { Com_Error( ERR_FATAL, "Bad map name: %s\n", sv_mapname->string ); } session.CurrentMap = index; session.GameType = sv_gametype->integer; // All other game options: session.FriendlyFire = g_friendlyFire.integer; session.JediMastery = g_maxForceRank.integer; session.SaberOnly = HasSetSaberOnly(); session.Dedicated = com_dedicated->integer; // Update the advertised session info session.Update(); }