void DestroyDialog(struct Dialog **dialog) { struct Dialog *d = *dialog; if (d != NULL) { DestroyDialogId(&d->id); DestroyUri(&d->remoteTarget); DestroyUri(&(d->remoteUri)); DestroySession(&d->session); free(d); *dialog = NULL; } }
void ClusterInterface::HandlePlayerLogin(WorldPacket & pck) { /* player x logging into instance y */ uint32 Guid, InstanceId, MapId; uint32 AccountId, Account_Flags, sessionid, ClientBuild; string GMPermissions, accountname; pck >> Guid >> MapId >> InstanceId >> AccountId >> Account_Flags >> sessionid >> GMPermissions >> accountname >> ClientBuild; /* find the instance */ Map* ma = sInstanceMgr.GetMap(MapId); ASSERT(ma); MapMgr* mm = sInstanceMgr.GetInstance(MapId, InstanceId); ASSERT(mm); /* create the session */ WorldSession * s = sWorld.FindSession(AccountId); /* create the socket */ WorldSocket * so = new WorldSocket(sessionid); if (s == NULL) s = new WorldSession(AccountId, accountname, so); _sessions[sessionid] = s; sWorld.AddSession(s); bool login_result = s->ClusterTryPlayerLogin(Guid, ClientBuild, GMPermissions, Account_Flags); if(login_result) { /* login was ok. send a message to the realm server telling him to distribute our info to all other realm server */ WorldPacket data(ICMSG_PLAYER_LOGIN_RESULT, 5); data << Guid << sessionid << uint8(1); SendPacket(&data); } else { /* for some reason the login failed */ WorldPacket data(ICMSG_PLAYER_LOGIN_RESULT, 5); data << Guid << sessionid << uint8(0); SendPacket(&data); /* tell the client his login failed before deleting the session */ data.Initialize(SMSG_CHARACTER_LOGIN_FAILED); data << uint8(62); so->SendPacket(&data); /* destroy the session */ DestroySession(sessionid); } }
void ClusterInterface::HandlePlayerLogin(WorldPacket & pck) { /* player x logging into instance y */ uint32 guid, instance, mapid; uint32 accountid, accountflags, sessionid; string gmpermissions, accountname; pck >> guid >> mapid >> instance >> accountid >> accountflags >> sessionid >> gmpermissions >> accountname; /* find the instance */ Map * ma = sWorldCreator.GetMap(mapid); ASSERT(ma); MapMgr * mm = ma->GetInstance(instance); ASSERT(mm); /* create the session */ WorldSession * s = sWorld.FindSession(accountid); ASSERT(!s); /* create the socket */ WorldSocket * so = new WorldSocket(sessionid); s = new WorldSession(accountid, accountname, so); _sessions[sessionid] = s; sWorld.AddSession(s); bool login_result = s->PlayerLogin(guid, mapid, instance); if(login_result) { /* login was ok. send a message to the realm server telling him to distribute our info to all other realm server */ WorldPacket data(ICMSG_PLAYER_LOGIN_RESULT, 5); data << guid << sessionid << uint8(1); SendPacket(&data); } else { /* for some reason the login failed */ WorldPacket data(ICMSG_PLAYER_LOGIN_RESULT, 5); data << guid << sessionid << uint8(0); SendPacket(&data); /* tell the client his login failed before deleting the session */ data.Initialize(SMSG_CHARACTER_LOGIN_FAILED); data << uint8(62); so->SendPacket(&data); /* destroy the session */ DestroySession(sessionid); } }
void SessionMgr::DestroyAllSessions() { SESSION_MAP::iterator it = m_Sessions.begin(); SESSION_MAP::iterator end = m_Sessions.end(); for (; end != it; ++it ) { if ( NULL != it->second ) { if( SessionActive( it->second->GetID() ) ) { #ifdef WIN32 if( SOCKET_ERROR == closesocket( it->second->GetSock() ) ) { int errNum = WSAGetLastError(); #elif defined(LINUX) if( -1 == close( it->second->GetSock() ) ) { int errNum = errno; #endif LOG_INFO( logger, __FUNCTION__ << " failed to close socket, session id:" << it->second->GetID() << ", socket: " << it->second->GetSock() << ", " << FormatErrorMessage( errNum ) ); } } DestroySession( it->second ); } } } int SessionMgr::GenerateSessionID() { MutexGuard guard( m_pMutex ); int sessionID = 0; if( !m_pFreeSessionID->Top( sessionID ) ) { return 0; } SetSessionActiveImpl( sessionID, true ); m_pFreeSessionID->Pop(); return sessionID; }
QTSS_Error QTSSProxyModuleDispatch(QTSS_Role inRole, QTSS_RoleParamPtr inParams) { switch (inRole) { case QTSS_Register_Role: return Register(&inParams->regParams); case QTSS_Initialize_Role: return Initialize(&inParams->initParams); case QTSS_RTSPRequest_Role: return ProcessRTSPRequest(&inParams->rtspRequestParams); case QTSS_ClientSessionClosing_Role: return DestroySession(&inParams->clientSessionClosingParams); case QTSS_RTCPProcess_Role: return ProcessIncomingRTCPPacket(&inParams->rtcpProcessParams); case QTSS_Shutdown_Role: return Shutdown(); } return QTSS_NoErr; }
void CslIrcEngine::DeinitEngine() { wxASSERT_MSG(m_thread!=NULL,wxT("Engine not initialised")); wxUint32 i; for (i=m_sessions.GetCount();i>0;i--) m_sessions.Item(i-1)->Disconnect(); if (m_thread) { m_thread->Terminate(); m_thread->Wait(); delete m_thread; } for (i=m_sessions.GetCount();i>0;i--) DestroySession(m_sessions.Item(i-1)); }
QTSS_Error QTSSOnDemandRelayModuleDispatch(QTSS_Role inRole, QTSS_RoleParamPtr inParams) { switch (inRole) { case QTSS_Register_Role: return Register(&inParams->regParams); case QTSS_Initialize_Role: return Initialize(&inParams->initParams); case QTSS_RereadPrefs_Role: return RereadPrefs(); case QTSS_RTSPPreProcessor_Role: return ProcessRTSPRequest(&inParams->rtspRequestParams); case QTSS_RTSPRelayingData_Role: return ProcessRelayRTPData(&inParams->rtspRelayingDataParams); case QTSS_ClientSessionClosing_Role: return DestroySession(&inParams->clientSessionClosingParams); } return QTSS_NoErr; }
QTSS_Error QTSSRTPFileModuleDispatch(QTSS_Role inRole, QTSS_RoleParamPtr inParamBlock) { switch (inRole) { case QTSS_Register_Role: return Register(&inParamBlock->regParams); case QTSS_Initialize_Role: return Initialize(&inParamBlock->initParams); case QTSS_RereadPrefs_Role: return RereadPrefs(); case QTSS_RTSPPreProcessor_Role: return ProcessRTSPRequest(&inParamBlock->rtspPreProcessorParams); case QTSS_RTPSendPackets_Role: return SendPackets(&inParamBlock->rtpSendPacketsParams); case QTSS_ClientSessionClosing_Role: return DestroySession(&inParamBlock->clientSessionClosingParams); } return QTSS_NoErr; }
//----------------------------------------------------------------------------- // Purpose: Create a new session //----------------------------------------------------------------------------- bool CSession::CreateSession() { if( INVALID_HANDLE_VALUE != m_hSession ) { Warning( "CreateSession called on existing session!" ); DestroySession(); m_hSession = INVALID_HANDLE_VALUE; } uint flags = m_nSessionFlags; if( m_bIsHost ) { flags |= XSESSION_CREATE_HOST; } if ( flags & XSESSION_CREATE_USES_ARBITRATION ) { m_bIsArbitrated = true; } m_hCreateHandle = g_pXboxSystem->CreateAsyncHandle(); // Create the session uint ret = g_pXboxSystem->CreateSession( flags, XBX_GetPrimaryUserId(), m_nPlayerSlots[SLOTS_TOTALPUBLIC], m_nPlayerSlots[SLOTS_TOTALPRIVATE], &m_SessionNonce, &m_SessionInfo, &m_hSession, true, &m_hCreateHandle ); if( ret != ERROR_SUCCESS && ret != ERROR_IO_PENDING ) { Warning( "XSessionCreate failed with error %d\n", ret ); return false; } SwitchToState( SESSION_STATE_CREATING ); return true; }
//----------------------------------------------------------------------------- // Purpose: Reset a session to it's initial state //----------------------------------------------------------------------------- void CSession::ResetSession() { // Cleanup first switch( m_SessionState ) { case SESSION_STATE_CREATING: CancelCreateSession(); break; case SESSION_STATE_MIGRATING: // X360TBD: break; } if ( m_hSession != INVALID_HANDLE_VALUE ) { Msg( "ResetSession: Destroying current session.\n" ); DestroySession(); m_hSession = INVALID_HANDLE_VALUE; } SwitchToState( SESSION_STATE_NONE ); m_bIsHost = false; m_bIsArbitrated = false; m_bUsingQoS = false; m_bIsSystemLink = false; Q_memset( &m_nPlayerSlots, 0, sizeof( m_nPlayerSlots ) ); Q_memset( &m_SessionInfo, 0, sizeof( m_SessionInfo ) ); if ( m_pRegistrationResults ) { delete m_pRegistrationResults; } m_nSessionFlags = 0; }
DWORD CloseDevice( DWORD_PTR private_handle) { MMRESULT result; SessionInfo* session_info = (SessionInfo*) private_handle; /* TODO: Maybe this is best off inside the playback thread? */ ASSERT(session_info); result = CallSessionThread(session_info, WODM_CLOSE, 0); if ( result == MMSYSERR_NOERROR ) { /* TODO: Wait for it to be safe to terminate */ CloseKernelDevice(session_info->kernel_device_handle); DestroySession(session_info); } return result; }
void* tsNode::run() { while (true) { try { for(;;) { int zevents = 0; size_t len = sizeof(zevents); mAuthSocket.getsockopt(ZMQ_EVENTS, &zevents, &len); if (!(zevents & ZMQ_POLLIN)) break; char msg[tsTick::SERIALIZEDMAXSIZE]; int msgSize = mAuthSocket.recv(msg, sizeof(msg), ZMQ_DONTWAIT); if (msgSize < tsTick::SERIALIZEDHEADSIZE) { printf("tsNode::run: invalid control message size %d\n", msgSize); break; } zmq::message_t msgMore; len = sizeof(int); int more = 0; mAuthSocket.getsockopt(ZMQ_RCVMORE, &more, &len); if (more) more = mAuthSocket.recv(&msgMore, ZMQ_DONTWAIT); ProcessControlMsg(msg, msgSize, more>0 ? &msgMore : NULL); } tsSocketSet socketSet; socketSet.addRdFD(mAuthSocketFD); socketSet.addRdFD(mClientListen.fd()); socketSet.addRdFD(mPipeListen.fd()); for(std::list<tsTickReceiver*>::const_iterator it = mPipeTCPConnections.begin(); it != mPipeTCPConnections.end(); ++it) socketSet.addRdFD((*it)->socketFD()); for(std::vector<tsSession*>::iterator it = mSessions.begin(); it != mSessions.end(); ) { if ((*it)->socketFD() == -1) { DestroySession(*it); it = mSessions.erase(it); } else { socketSet.addRdFD((*it)->socketFD()); ++it; } } if (socketSet.select()) { for(std::list<tsTickReceiver*>::iterator it = mPipeTCPConnections.begin(); it != mPipeTCPConnections.end(); ) { if (socketSet.testRdFD((*it)->socketFD())) { if (!(*it)->receiveTicks(0)) { printf("%s: closing pipe TCP connection with fd %d\n", __FUNCTION__, (*it)->socketFD()); delete *it; it = mPipeTCPConnections.erase(it); continue; } } ++it; } for(std::vector<tsSession*>::iterator it = mSessions.begin(); it != mSessions.end(); ) { if (socketSet.testRdFD((*it)->socketFD())) { if (!(*it)->receiveTicks(0)) { DestroySession(*it); it = mSessions.erase(it); continue; } } ++it; } if (socketSet.testRdFD(mPipeListen.fd()) && (mPipeTCPConnections.size() < MaxPipeConnections)) { int newSocketPipe = mPipeListen.accept(); printf("%s: new pipe connection on %s with fd %d\n", __FUNCTION__, mPipeListen.nameinfo().c_str(), newSocketPipe); tsTickReceiver* pReceiver = new tsTickReceiver(this, newSocketPipe); mPipeTCPConnections.push_back(pReceiver); } if (socketSet.testRdFD(mClientListen.fd()) && (mSessions.size() < MaxClientConnections)) { int newSocketOut = mClientListen.accept(); printf("%s: new client connection on %s with fd %d\n", __FUNCTION__, mClientListen.nameinfo().c_str(), newSocketOut); tsSession* pSession = new tsSession(*this, newSocketOut, mNextSessionID++); mSessions.push_back(pSession); } } } catch(std::exception& e) { printf("tsNode::run: %s\n", e.what()); } } printf("%s: shutting down\n", __FUNCTION__); // close all TCP connections for(std::list<tsTickReceiver*>::reverse_iterator it = mPipeTCPConnections.rbegin(); it != mPipeTCPConnections.rend(); ++it) delete (*it); mPipeTCPConnections.clear(); return NULL; }
DWORD OpenDevice( DeviceType device_type, UINT device_id, PVOID open_descriptor, DWORD flags, DWORD_PTR private_handle) { SessionInfo* session_info; MMRESULT result; DWORD message; /* This will automatically check for duplicate sessions */ result = CreateSession(device_type, device_id, &session_info); if ( result != MMSYSERR_NOERROR ) { DPRINT("Couldn't allocate session info\n"); return result; } result = OpenKernelDevice(device_type, device_id, GENERIC_READ, &session_info->kernel_device_handle); if ( result != MMSYSERR_NOERROR ) { DPRINT("Failed to open kernel device\n"); DestroySession(session_info); return result; } /* Set common session data */ session_info->flags = flags; /* Set wave/MIDI specific data */ if ( IsWaveDevice(device_type) ) { LPWAVEOPENDESC wave_open_desc = (LPWAVEOPENDESC) open_descriptor; session_info->callback = wave_open_desc->dwCallback; session_info->mme_wave_handle = wave_open_desc->hWave; session_info->app_user_data = wave_open_desc->dwInstance; } else { DPRINT("Only wave devices are supported at present!\n"); DestroySession(session_info); return MMSYSERR_NOTSUPPORTED; } /* Start the processing thread */ result = StartSessionThread(session_info); if ( result != MMSYSERR_NOERROR ) { DestroySession(session_info); return result; } /* Store the session info */ *((SessionInfo**)private_handle) = session_info; /* Send the right message */ message = (device_type == WaveOutDevice) ? WOM_OPEN : (device_type == WaveInDevice) ? WIM_OPEN : (device_type == MidiOutDevice) ? MOM_OPEN : (device_type == MidiInDevice) ? MIM_OPEN : 0xFFFFFFFF; NotifyClient(session_info, message, 0, 0); return MMSYSERR_NOERROR; }
/***************************************************************************** IsSlowTransport CAVEAT: THIS CALL MAY LEAVE A SESSION TO THE SERVER IF A SLOW TRANSPORT IS DETECTED BECAUSE THE WORKER THREAD MAY STILL BE MAKING API CALLS AFTER THE TIMEOUT CAUSING THE NETUSEDEL(with NOFORCE) TO BE INEFFECTUAL. *****************************************************************************/ APIERR IsSlowTransport( const TCHAR FAR * pszServer, BOOL FAR * pfSlowTransport ) { APIERR err = NERR_Success; BOOL fSessionSetup=FALSE; DWORD resWait; DWORD idThread; HANDLE hThread; *pfSlowTransport = FALSE; // return immediately if pszServer is NULL if (pszServer == NULL || *pszServer == 0) { *pfSlowTransport = FALSE; return(NERR_Success); } // // Initialize. // err = NERR_Success; errThread = NERR_Success; // // Set up the session. // err = SetupNormalSession (pszServer); if (err == NERR_Success) { fSessionSetup = TRUE; } else if (err == ERROR_SESSION_CREDENTIAL_CONFLICT) { err = NERR_Success; } else { err = SetupNullSession (pszServer); if (err != NERR_Success) return(err); fSessionSetup = TRUE; } do // false loop { // // Create the worker thread. // hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)SlowTransportWorkerThread, (LPVOID)pszServer, 0, &idThread ); if( hThread == NULL ) { err = (APIERR) GetLastError(); break; } // // Wait for either the thread to complete or a timeout. // resWait = WaitForSingleObject( hThread, MAXWAITTIME ); CloseHandle( hThread ); hThread = NULL; // // Interpret the results. // if( resWait == -1 ) { err = (APIERR)GetLastError(); break; } switch (resWait) { case WAIT_TIMEOUT: *pfSlowTransport = TRUE; break; case WAIT_OBJECT_0: if (errThread == NERR_Success) { *pfSlowTransport = FALSE; } break; default: err = ERROR_NOT_ENOUGH_MEMORY; break; } } while ( FALSE ); // // Destroy the session if we managed to create one. // if (fSessionSetup) { DestroySession( pszServer ); } return ( (err != NERR_Success) ? err : errThread ); } // IsSlowTransport
/***************************************************************************** SetupSession *****************************************************************************/ APIERR SetupSession( const TCHAR * pszServer ) { APIERR err; WKSTA_INFO_100 * pwki100 = NULL; // // Connect to the target server. // err = SetupNullSession( pszServer ); if( err == NERR_Success ) // NULL session established. { BOOL fIsDownlevel = FALSE; // // Determine target type. // err = NetWkstaGetInfo( (LPTSTR)pszServer, 100, (LPBYTE *)&pwki100 ); if( ( err == ERROR_ACCESS_DENIED ) || ( ( err == NERR_Success ) && ( pwki100->wki100_platform_id == SV_PLATFORM_ID_OS2 ) ) ) { // // The target is downlevel. // fIsDownlevel = TRUE; } if( ( err != NERR_Success ) || fIsDownlevel ) { // // Either we cannot talk to the server, or it's // downelevel, so blow away the NULL session. // DestroySession( pszServer ); } if( fIsDownlevel ) { // // It's a downlevel server. There aren't many useful // API we can remote to a downlevel server over a NULL // session, (and we just blew away the NULL session // anyway) so try a "normal" session. // err = SetupNormalSession( pszServer ); } if( pwki100 != NULL ) { NetApiBufferFree( (LPVOID)pwki100 ); } } return(err); }