void SMOnlineRoom::UpdateClients() { int length = 0; for (unsigned int x = 0; x < m_clients.size(); ++x) { if (!m_clients[x]) { LOG->Write("Error: Trying to update NULL client"); RemoveClient(x); continue; } try { do { //As long as we keep getting data from the socket, keep processing it length = m_clients[x]->Update(m_packet); if (length > 0) ParseData(m_packet, x); //Check for NULL incase the client switched rooms } while ((length > 0) && (x < m_clients.size()) && (m_clients[x])); } catch (ClientError&) { RemoveClient(x); } } }
void OnSelect(SocketHandle handle, Network::ISelector::SelectType selectType) { try { ClientPool::iterator Iter = Clients.find(handle); assert(Iter != Clients.end() && "Client not found"); if (Iter == Clients.end()) return; switch (selectType) { case Network::ISelector::stRead : { try { Iter->second->RecvData(); } catch (...) { RemoveClient(Iter); throw; } } return; case Network::ISelector::stClose : RemoveClient(Iter); return; default : break; } } catch (std::exception const &e) { Common::Log::GetLogInst() << e.what(); } }
void TestClient::Shutdown() { m_bRun = false; while (ConvertIntToDWORD(m_ExitCount) != m_InitData.ThreadNum * 2 + 1) Sleep(10); for (int i = 0; i < MAX_CLIENT_THREAD; ++i) { while (m_NewRecvList[i].HasItem()) RemoveClient(m_NewRecvList[i].GetItem()); while (m_NewSendList[i].HasItem()) RemoveClient(m_NewSendList[i].GetItem()); } }
static void ClientDataRX (int fd, void *userData) { RADSOCK_ID client = (RADSOCK_ID)userData; int retVal; ULONG dateTime; retVal = datafeedSyncStartOfFrame(client); switch (retVal) { case ERROR: /* problems! - bail out */ statusUpdateMessage("ClientDataRX: socket error during sync - disconnecting"); radMsgLog (PRI_HIGH, "ClientDataRX: socket error during sync - disconnecting"); RemoveClient(client); break; case ERROR_ABORT: // This guy has bailed out: statusUpdateMessage("ClientDataRX: socket far-end closed"); radMsgLog (PRI_MEDIUM, "ClientDataRX: socket far-end closed"); RemoveClient(client); break; case FALSE: radMsgLog (PRI_STATUS, "ClientDataRX: RX sync failure - ignoring"); break; case DF_RQST_ARCHIVE_PKT_TYPE: // OK, read the unix time sent to retrieve the record: if (radSocketReadExact(client, (void *)&dateTime, sizeof(dateTime)) != sizeof (dateTime)) { statusUpdateMessage("ClientDataRX: socket read error - disconnecting"); radMsgLog (PRI_HIGH, "ClientDataRX: socket read error - disconnecting"); RemoveClient(client); break; } // Convert from network byte order: dateTime = ntohl(dateTime); // Now we have the date and time, get busy: SendNextArchiveRecord(client, dateTime); break; } return; }
/** Destroy a confirm dialog. */ void DestroyConfirmDialog(DialogType *dp) { int x; Assert(dp); /* This will take care of destroying the dialog window since * its parent will be destroyed. */ RemoveClient(dp->node); for(x = 0; x < dp->lineCount; x++) { Release(dp->message[x]); } Release(dp->message); if(dp->next) { dp->next->prev = dp->prev; } if(dp->prev) { dp->prev->next = dp->next; } else { dialogList = dp->next; } Release(dp); }
/* Обрабатывает входящий пакет Для вызова нужно заблокировать мютекс pthread_mutex_lock(pinf->mutex); */ void ReadMSG(PTINF *pinf, MSG msg) { /* Эта функция обрабатывает сообщени. Если клиент известный, то отправляем ему его-же сообщение и удаляем его. (При подключении, в функции CheckNewClients, сервер отправляет время) */ socklen_t sl; SADDR addr; int sid = msg.sid; time_t now_time; if(sid < 0 || sid >= MAX_PTH_CLIENTS){ printf("Unkown client: %d\n", sid); return; } sl = SADDR_SIZE; CopySADDR(*pinf->addr[sid], &addr); time(&now_time); //printf("%s\t%s(%d): %s\n", ctime(&now_time), inet_ntoa(addr.sin_addr), htons(addr.sin_port), msg.data_str); if(sendto(pinf->sock_d, &msg, MSG_SIZE, 0, (struct sockaddr *) &addr, sl) < 0) perror("Error re-send"); RemoveClient(pinf, sid); }
void CameraObject::Release( View * view ) { if( view->GetType() == THREED_VIEW_TYPE ) { PerViewElementCont::iterator it = m_perViewElements.find( view ); if( it != m_perViewElements.end() ) { PerViewElements & perView = (*it).second; view->GetRenderer()->RemoveViewProp( perView.cameraActor ); perView.cameraActor->Delete(); view->GetRenderer()->RemoveViewProp( perView.cameraAxesActor ); perView.cameraAxesActor->Delete(); view->GetRenderer()->RemoveViewProp( perView.cameraTrackerAxesActor ); perView.cameraTrackerAxesActor->Delete(); view->GetRenderer()->RemoveViewProp( perView.cameraImageActor ); perView.cameraImageActor->Delete(); if( perView.cameraBackup ) { ReleaseControl( 0 ); } ClearDrawingOneView( view, perView ); m_perViewElements.erase( it ); disconnect( this, SIGNAL(ObjectModified()), view, SLOT(NotifyNeedRender()) ); RemoveClient(); view->RemoveInteractionObject(this); } } }
void CDiscArena::Reset( void ) { // Remove all clients in the queue for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { CBasePlayer *pPlayer = (CBasePlayer *)UTIL_PlayerByIndex( i ); if (pPlayer && (pPlayer->m_pCurrentArena == this) && pPlayer->m_bHasDisconnected != TRUE ) { RemoveClient( pPlayer ); // Move her into spectator mode //MoveToSpectator( pPlayer ); } } m_pPlayerQueue = NULL; m_iPlayers = 0; m_flTimeLimitOver = 0; m_bShownTimeWarning = FALSE; m_iArenaState = ARENA_WAITING_FOR_PLAYERS; memset( m_hCombatants, 0, sizeof( m_hCombatants ) ); SetThink( NULL ); pev->nextthink = 0; }
static void PurgeStaleClients() { if (ipcClientCount == 0) return; LOG(("PurgeStaleClients [num-clients=%u]\n", ipcClientCount)); // // walk the list of supposedly active clients, and verify the existance of // their respective message windows. // char wName[IPC_CLIENT_WINDOW_NAME_MAXLEN]; for (int i=ipcClientCount-1; i>=0; --i) { ipcClient *client = &ipcClientArray[i]; LOG((" checking client at index %u [client-id=%u pid=%u]\n", i, client->ID(), client->PID())); IPC_GetClientWindowName(client->PID(), wName); // XXX dougt has ideas about how to make this better HWND hwnd = FindWindow(IPC_CLIENT_WINDOW_CLASS, wName); if (!hwnd) { LOG((" client window not found; removing client!\n")); RemoveClient(client); } } }
~iWARPEM_Multiplexed_Endpoint_t() { bzero( &mRouterInfo, sizeof( iWARPEM_Router_Info_t )); // go over all active EPs and flush/destroy them for( int i=0; i < mMaxClientCount; i++ ) if( IsValidClient( i ) ) RemoveClient( i ); delete mClientEPs; delete mSendBuffer; delete mReceiveBuffer; pthread_spin_destroy( &mAccessLock ); BegLogLine( FXLOG_IT_API_O_SOCKETS_MULTIPLEX_LOG ) << "Destroyed multiplexed router endpoint." << " socket: " << mRouterConnFd << EndLogLine; #ifdef MULTIPLEX_STATISTICS BegLogLine( 1 ) << "average message count per send buffer:" << mMsgAvg << EndLogLine; #endif }
/* Sets up the TMDIFrame by constructing and creating its TMDIClient. */ void TMDIFrame::SetupWindow() { HMENU FrameMenu; RECT R; InitClientWindow(); RemoveClient(); // remove ClientWnd from OWL child list FrameMenu = GetMenu(HWindow); ClientWnd->ClientAttr->hWindowMenu = GetSubMenu(FrameMenu, ChildMenuPos); GetClientRect(HWindow, &R); if ( ClientWnd->Attr.X == CW_USEDEFAULT ) { ClientWnd->Attr.X = R.left; ClientWnd->Attr.Y = R.top; } if ( ClientWnd->Attr.W == CW_USEDEFAULT ) { ClientWnd->Attr.W = R.right - R.left; ClientWnd->Attr.H = R.bottom - R.top; } // allow client area to grow scroll bars if necessary. ClientWnd->Attr.Style |= WS_VSCROLL + WS_HSCROLL; if ( ClientWnd->Create() ) TWindow::SetupWindow(); else Status = EM_INVALIDCLIENT; }
void CSyncer::InstallClientDiff(const string& diff) { istringstream i(diff); int client; string name; bool wasRemove; int count; while (i >> client) { i >> wasRemove; //Handle remove if so if (wasRemove) { RemoveClient(client); return; } // Alas, it was not.. i >> count; for (int a = 0; a < count; ++a) { i >> name; map<string, DisabledUnit>::iterator found = disabledUnits.find(name); if (found != disabledUnits.end()) { disabledUnits[name].clients.insert(client); } else { DisabledUnit mu; mu.clients.insert(client); disabledUnits[name] = mu; } } } }
bool ClientController::DeleteClient(const Client &client) { if(!(UserSingleton::GetInstance().GetPermissions() & PLM::PermissionsFlag::WRITE_CLIENTS)) { return false; } QSqlQuery query = GetDb().CreateQuery(); query.prepare("DELETE FROM \"Client\" WHERE \"ClientId\"=:clientId"); query.bindValue(":clientId", client.GetClientId()); if(!query.exec()) { return false; } if(!DeleteContact(client)) { return false; } qint32 clientId = client.GetClientId(); RemoveClient(clientId); return true; }
void Server::PostSend(Client* client, Packet* packet) { assert(client); assert(packet); WSABUF recvBufferDescriptor; recvBufferDescriptor.buf = reinterpret_cast<char*>(packet->GetData()); recvBufferDescriptor.len = packet->GetSize(); DWORD sendFlags = 0; IOEvent* event = IOEvent::Create(IOEvent::SEND, client, packet); assert(event); StartThreadpoolIo(client->GetTPIO()); if (WSASend(client->GetSocket(), &recvBufferDescriptor, 1, NULL, sendFlags, &event->GetOverlapped(), NULL) == SOCKET_ERROR) { int error = WSAGetLastError(); if (error != ERROR_IO_PENDING) { CancelThreadpoolIo(client->GetTPIO()); ERROR_CODE(error, "WSASend() failed."); RemoveClient(client); } } else { // In this case, the completion callback will have already been scheduled to be called. } }
static void ProcessMsg(HWND hwnd, PRUint32 pid, const ipcMessage *msg) { LOG(("ProcessMsg [pid=%u len=%u]\n", pid, msg->MsgLen())); ipcClient *client = GetClientByPID(pid); if (client) { // // if this is an IPCM "client hello" message, then reset the client // instance object. // if (msg->Target().Equals(IPCM_TARGET) && IPCM_GetType(msg) == IPCM_MSG_REQ_CLIENT_HELLO) { RemoveClient(client); client = NULL; } } if (client == NULL) { client = AddClient(hwnd, pid); if (!client) return; } IPC_DispatchMsg(client, msg); }
SMOnlineRoom::~SMOnlineRoom() { while (m_clients.size() > 0) RemoveClient(m_clients.size()-1); while (m_joinrooms.size() > 0) UnjoinToRoom(m_joinrooms[m_joinrooms.size()-1]->m_title); }
void Server::AddClient(Client* client) { assert(client); // The socket sAcceptSocket does not inherit the properties of the socket associated with // sListenSocket parameter until SO_UPDATE_ACCEPT_CONTEXT is set on the socket. if (setsockopt(client->GetSocket(), SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, reinterpret_cast<const char*>(&m_listenSocket), sizeof(m_listenSocket)) == SOCKET_ERROR) { ERROR_CODE(WSAGetLastError(), "setsockopt() for AcceptEx() failed."); RemoveClient(client); } else { client->SetState(Client::ACCEPTED); // Connect the socket to IOCP TP_IO* pTPIO = CreateThreadpoolIo(reinterpret_cast<HANDLE>(client->GetSocket()), Server::IoCompletionCallback, NULL, NULL); if (pTPIO == NULL) { ERROR_CODE(GetLastError(), "CreateThreadpoolIo failed for a client."); RemoveClient(client); } else { std::string ip; u_short port = 0; Network::GetRemoteAddress(client->GetSocket(), ip, port); TRACE("[%d] Accept succeeded. client address : ip[%s], port[%d]", GetCurrentThreadId(), ip.c_str(), port); client->SetTPIO(pTPIO); EnterCriticalSection(&m_CSForClients); m_Clients.push_back(client); LeaveCriticalSection(&m_CSForClients); PostRecv(client); } } }
void TestClient::SendThread() { vector<ClientData*> clientList; UINT halfTick = m_InitData.Timeout >> 1; NetCmd nc; nc.SetCmdSize(sizeof(nc)); nc.SetCmdType(ConvertDWORDToWORD(m_InitData.CmdHearbeat)); long threadIdx = ::InterlockedIncrement(&m_SendIndex) - 1; SafeList<ClientData*> &sendList = m_NewSendList[threadIdx]; Timer t; t.Begin(); while (m_bRun) { while (sendList.HasItem()) clientList.push_back(sendList.GetItem()); UINT tick = GetTickCount(); for (UINT i = 0; i < clientList.size();) { ClientData *pc = clientList[i]; if (pc->InsideRemoved) { RemoveClient(pc); ListRemoveAt(clientList, i); continue; } if (tick - pc->SendTick > halfTick) { int nret = send(pc->Socket, (const char*)&nc, nc.CmdSize, 0); if (nret != nc.CmdSize) { Log(L"send hearbeat err:%d, lastErr:%d", nret, WSAGetLastError()); } pc->SendTick = tick; } ++i; } m_SendData[threadIdx].Num = clientList.size(); m_SendData[threadIdx].Delta = t.Intecept(); Sleep(m_InitData.SleepTime); } for (UINT i = 0; i < clientList.size(); ++i) RemoveClient(clientList[i]); ::InterlockedIncrement(&m_ExitCount); }
//============================================================================ // NMessageServer::DisconnectClient : Disconnect a client. //---------------------------------------------------------------------------- void NMessageServer::DisconnectClient(NEntityID clientID) { StLock acquireLock(mLock); // Disconnect the client ClientDisconnected(clientID); RemoveClient( clientID); }
/** Handle an unmap notify event. */ void HandleUnmapNotify(const XUnmapEvent *event) { ClientNode *np; XEvent e; Assert(event); if(event->window != event->event) { /* Allow ICCCM synthetic UnmapNotify events through. */ if (event->event != rootWindow || !event->send_event) { return; } } np = FindClientByWindow(event->window); if(np) { /* Grab the server to prevent the client from destroying the * window after we check for a DestroyNotify. */ GrabServer(); if(np->controller) { (np->controller)(1); } if(JXCheckTypedWindowEvent(display, np->window, DestroyNotify, &e)) { UpdateTime(&e); RemoveClient(np); } else if((np->state.status & STAT_MAPPED) || event->send_event) { if(!(np->state.status & STAT_HIDDEN)) { np->state.status &= ~STAT_MAPPED; JXUngrabButton(display, AnyButton, AnyModifier, np->window); GravitateClient(np, 1); JXReparentWindow(display, np->window, rootWindow, np->x, np->y); WriteState(np); JXRemoveFromSaveSet(display, np->window); RemoveClient(np); } } UngrabServer(); } }
/* Constructor for a TMDIFrame which is being used in a DLL as an alias for a non-OWL window */ TMDIFrame::TMDIFrame(HWND AnHWindow, HWND ClientHWnd, PTModule AModule) : TWindow(AnHWindow, AModule) { // Attr.Menu set in TWindow's constructor ChildMenuPos = 0; ActiveChild = NULL; ClientWnd = new TMDIClient(this, ClientHWnd); RemoveClient(); // remove ClientWnd from OWL child list SetFlags(WB_MDIFRAME | WB_ALIAS, TRUE); }
int UserRoom::RemoveClientByStream(css_stream_t* stream) { UserClient* tmp = clients_; while (tmp){ if (tmp->stream() == stream){ return RemoveClient(tmp); } tmp = tmp->next(); } return -1; }
void OnIdle() { try { for (ClientPool::iterator i = Clients.begin() ; i != Clients.end() ; ) { if (i->second->CanClose()) RemoveClient(i++); else { try { i->second->OnIdle(); if (i->second->CanClose()) RemoveClient(i++); else ++i; } catch (std::exception const &e) { Clients.erase(i++); Common::Log::GetLogInst() << e.what(); } } } if (Clients.size() >= MaxConnections) return; ClientItemPtr Client = AcceptedClients->Pop(); if (!Client.get()) return; Selector.AddSocket(Client->GetHandle(), Network::ISelector::stRead | Network::ISelector::stClose); Clients[Client->GetHandle()] = Client; } catch (std::exception const &e) { Common::Log::GetLogInst() << e.what(); } }
/** Release client windows. */ void ShutdownClients(void) { int x; for(x = 0; x < LAYER_COUNT; x++) { while(nodeTail[x]) { RemoveClient(nodeTail[x]); } } }
void CloseSession( PCLIENT pc ) { if( pc->ssl_session ) { //matrixSslDeleteSessionId(pc->ssl_session->sid); Release( pc->ssl_session ); pc->ssl_session = NULL; } if( !( pc->dwFlags & ( CF_CLOSED|CF_CLOSING ) ) ) RemoveClient( pc ); }
/** Handle a destroy notify event. */ char HandleDestroyNotify(const XDestroyWindowEvent *event) { ClientNode *np; np = FindClientByWindow(event->window); if(np) { if(np->controller) { (np->controller)(1); } RemoveClient(np); return 1; } else { return HandleDockDestroy(event->window); } }
// 与服务器断开连接 bool CNetProc::Close(const char* ip, const int port) { std::string key = format_key(ip, port); CBoostGuard lock(&m_clientLock); if (-1 == GetClientHandle(key)) { return true; } lt_client_disconnect(GetClientHandle(key)); RemoveClient(key); return true; }
void Server::OnClose(IOEvent* event) { assert(event); TRACE("Client's socket has been closed."); // If whatever game logics about this event are fast enough, we can manage them here but I // assume they are slow. if (!m_ShuttingDown && !TrySubmitThreadpoolCallback(Server::WorkerRemoveClient, event->GetClient(), &m_ClientTPENV)) { ERROR_CODE(GetLastError(), "can't start WorkerRemoveClient. call it directly."); RemoveClient(event->GetClient()); } }
/** * Register Client */ HRESULT CDIL_CAN_i_VIEW::CAN_RegisterClient( BOOL Register, DWORD& ClientID, char* ClientName ) { USES_CONVERSION; HRESULT hResult = S_FALSE; EnterCriticalSection(&m_Mutex); if (Register) { if (m_Clients.size() < MAX_CLIENT_ALLOWED) { pClient_t pClient= GetClient(ClientName); if (!pClient) { pClient = new Client(ClientName); ClientID = pClient->m_ClientID; AddClient( pClient ); hResult = S_OK; } else { ClientID = pClient->m_ClientID; hResult = ERR_CLIENT_EXISTS; } } else { hResult = ERR_NO_MORE_CLIENT_ALLOWED; } } else { if (RemoveClient(ClientID)) { hResult = S_OK; } else { hResult = ERR_NO_CLIENT_EXIST; } } LeaveCriticalSection(&m_Mutex); return hResult; }
/** Callback to kill a client after a confirm dialog. */ void KillClientHandler(ClientNode *np) { Assert(np); if(np == activeClient) { FocusNextStacked(np); } GrabServer(); JXKillClient(display, np->window); JXSync(display, True); UngrabServer(); RemoveClient(np); }