bool ServerManager::ProcessCommands( ) { bool ret = false; if(m_MinFD == INVALID_SOCKET && m_MaxFD == INVALID_SOCKET) { return true; } for(int i=SCENE_PLAYER_ID; i<=BILLING_PLAYER_ID; i++) { ServerPlayer* pPlayer = GetServerPlayer(i); if(!pPlayer) continue; if(pPlayer->IsValid()) { if(pPlayer->GetSocket()->isSockError() ) { RemoveServer(i); } else { ret = pPlayer->ProcessCommand(false); if(!ret) { RemoveServer( i ); } } } } return true; }
/** * \fn UPNPScanner::AddServer(const QString&, const QString&) * Adds the server identified by usn and reachable via url to the list of * known media servers and schedules an update to initiate a connection. */ void UPNPScanner::AddServer(const QString &usn, const QString &url) { if (url.isEmpty()) { RemoveServer(usn); return; } // sometimes initialisation is too early and m_masterHost is empty if (m_masterHost.isEmpty()) { m_masterHost = gCoreContext->GetSetting("MasterServerIP"); m_masterPort = gCoreContext->GetSettingOnHost("BackendStatusPort", m_masterHost, "6544").toInt(); } QUrl qurl(url); if (qurl.host() == m_masterHost && qurl.port() == m_masterPort) { LOG(VB_UPNP, LOG_INFO, LOC + "Ignoring master backend."); return; } m_lock.lock(); if (!m_servers.contains(usn)) { m_servers.insert(usn, new MediaServer(url)); LOG(VB_GENERAL, LOG_INFO, LOC + QString("Adding: %1").arg(usn)); ScheduleUpdate(); } m_lock.unlock(); }
bool ServerManager::ProcessExceptions( ) { if(m_MinFD == INVALID_SOCKET && m_MaxFD == INVALID_SOCKET) { return true; } for(int i=SCENE_PLAYER_ID; i<=BILLING_PLAYER_ID; i++) { ServerPlayer* pPlayer = GetServerPlayer(i); if(!pPlayer) continue; if(pPlayer->IsValid()) { SOCKET s = pPlayer->GetSocket()->getSOCKET(); if(FD_ISSET( s, &m_ExceptFDs[SELECT_USE]) ) { g_pLog->log_debug("%u,%u,ProcessException......",pPlayer->PlayerID(),0); RemoveServer(i); } } } return true; }
LRESULT CServerMonitorView::OnBnClickedStopAllMonitoring(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled) { while (m_ServerList.GetSize() > 0) { RemoveServer(m_ServerList[0]); } return 0; }
VOID CloseAsc(ASSOC_IPC * asipc) { int i = 0; /* ** If we are a gcc let the client disconnect first. If ten seconds ** elapse then disconnect anyways. */ while( is_gcc && asipc->IpcInternal.AssocInfo->bPipesClosed == FALSE && i++ < 200 ) PCsleep(50); if (asipc->SndStdChan) CloseHandle(asipc->SndStdChan); if (asipc->RcvStdChan) { WriteFile(asipc->RcvStdChan, "", 1, &i, NULL); Sleep(0); CloseHandle(asipc->RcvStdChan); } if (asipc->SndExpChan) CloseHandle(asipc->SndExpChan); if (asipc->RcvExpChan) { WriteFile(asipc->RcvExpChan, "", 1, &i, NULL); Sleep(0); CloseHandle(asipc->RcvExpChan); } if (asipc->ClientReadHandle) CloseHandle(asipc->ClientReadHandle); /* Mark pipes as being closed. */ if ( asipc->IpcInternal.AssocInfo ) { asipc->IpcInternal.AssocInfo->bPipesClosed = TRUE; asipc->IpcInternal.AssocInfo->refs--; /* decrement reference ct */ asipc->IpcInternal.AssocInfo = NULL; } asipc->SndStdChan = NULL; asipc->RcvStdChan = NULL; asipc->SndExpChan = NULL; asipc->RcvExpChan = NULL; asipc->ClientReadHandle = NULL; if ( asipc->IpcInternal.server ) { asipc->IpcInternal.server->nConnections--; if ( 0 == asipc->IpcInternal.server->nConnections ) RemoveServer( asipc->IpcInternal.server ); } return; }
void CServerList::RemoveDeadServers() { if ( thePrefs::DeadServer() ) { for ( CInternalList::const_iterator it = m_servers.begin(); it != m_servers.end(); ) { CServer* server = *it++; if ( server->GetFailedCount() > thePrefs::GetDeadserverRetries() && !server->IsStaticMember()) { RemoveServer(server); } } } }
void CServerListCtrl::RemoveAllDeadServers() { ShowWindow(SW_HIDE); for(POSITION pos = server_list->list.GetHeadPosition(); pos != NULL;server_list->list.GetNext(pos)) { CServer* cur_server = server_list->list.GetAt(pos); if (cur_server->GetFailedCount() >= thePrefs.GetDeadserverRetries()){ RemoveServer(cur_server); pos = server_list->list.GetHeadPosition(); } } ShowWindow(SW_SHOW); }
void CServerList::FilterServers() { CInternalList::iterator it = m_servers.begin(); while (it != m_servers.end()) { CServer* server = *it++; if (server->HasDynIP()) { continue; } if (theApp->ipfilter->IsFiltered(server->GetIP(), true)) { if (server == theApp->serverconnect->GetCurrentServer()) { AddLogLineC(_("Local server is filtered by the IPFilters, reconnecting to a different server!")); theApp->serverconnect->Disconnect(); RemoveServer(server); theApp->serverconnect->ConnectToAnyServer(); } else { RemoveServer(server); } } } }
bool ServerManager::ProcessOutputs( ) { bool ret = false; if(m_MinFD == INVALID_SOCKET && m_MaxFD == INVALID_SOCKET) { return true; } for(int i=SCENE_PLAYER_ID; i<=BILLING_PLAYER_ID; i++) { ServerPlayer* pPlayer = GetServerPlayer(i); if(!pPlayer) continue; if(pPlayer->IsValid()) { SOCKET s = pPlayer->GetSocket()->getSOCKET(); if(FD_ISSET( s, &m_WriteFDs[SELECT_USE]) ) { if(pPlayer->GetSocket()->isSockError() ) { RemoveServer(i); } else { ret = pPlayer->ProcessOutput( ); if(!ret) { RemoveServer( i ); } } } } } return true; }
void CServerListCtrl::RemoveAllFilteredServers() { if (!thePrefs.GetFilterServerByIP()) return; ShowWindow(SW_HIDE); for (POSITION pos = theApp.serverlist->list.GetHeadPosition(); pos != NULL; theApp.serverlist->list.GetNext(pos)) { const CServer* cur_server = theApp.serverlist->list.GetAt(pos); if (theApp.ipfilter->IsFiltered(cur_server->GetIP())) { if (thePrefs.GetLogFilteredIPs()) AddDebugLogLine(false, _T("Filtered server \"%s\" (IP=%s) - IP filter (%s)"), cur_server->GetListName(), ipstr(cur_server->GetIP()), theApp.ipfilter->GetLastHit()); RemoveServer(cur_server); pos = theApp.serverlist->list.GetHeadPosition(); } } ShowWindow(SW_SHOW); }
void ChannelBalancer::RemoveAndDestroyChannel(SelectiveChannel::ChannelHandle handle) { if (!RemoveServer(ServerId(handle))) { return; } SocketUniquePtr ptr; const int rc = Socket::AddressFailedAsWell(handle, &ptr); if (rc >= 0) { SubChannel* sub = static_cast<SubChannel*>(ptr->user()); { BAIDU_SCOPED_LOCK(_mutex); CHECK_EQ(1UL, _chan_map.erase(sub->chan)); } { SocketUniquePtr ptr2(ptr.get()); // Dereference. } if (rc == 0) { ptr->ReleaseAdditionalReference(); } } }
// ************************************************************************** // DeleteContents () // // Description: // Reset the document object for reuse. This includes disconnect from all // OPC servers and deleting all server objects. // // Parameters: // none // // Returns: // void // ************************************************************************** void CKDocument::DeleteContents () { // Create a wait cursor object. This will cause the wait cursor, // usually an hourglass, to be displayed. When this object goes // out of scope, its destructor will restore the previous cursor // type. CWaitCursor wc; // Update status bar text to indicate that we are unloading project: CKStatusBarText cText (IDS_UNLOADING_PROJECT); // Notify all views that the project is closing so that no request for // server/group/item is made (as in OnGetDispInfo) for a deleted object: UpdateAllViews (NULL, HINT_CLOSE_PROJECT, NULL); // Free all server connections maintained by the document. Start with // head of linked list and work our way to end: while (m_pServerHead) { // Need to make a copy of current head of linked list: CKServer *pServer = m_pServerHead; // Reset linked list head to next server: m_pServerHead = pServer->GetNext (); // Delete server (previously the head of linked list): RemoveServer (pServer); } // Check that we deleted all servers in linked list (debug only): ASSERT (m_cdwServers == 0); // Invalidate currently selected server and group: m_pCurSelServer = NULL; m_pCurSelGroup = NULL; // Default processing: CDocument::DeleteContents (); }
int RGClient :: Send (int serverId, unsigned char* sendBuffer, unsigned char*& replyBuffer, int sendLength, int& replyMax) { int len; LastError = RGOK; if (serverId <= 0) { LastError = RGILLEGALSERVERID; return -1; } RGServerPort* port = ServerPortList.GetElementAt (serverId); if (port == NULL) { LastError = RGSERVERNULL; return -1; } *ServerPid = port->GetServerPid (); int status = port->Send (sendLength, sendBuffer); if (status < 0) { LastError = port->GetLastError (); RemoveServer (serverId); return -1; } HANDLE HandleArray [2]; HandleArray [0] = port->GetServerHandle (); HandleArray [1] = OKToReadHandle; status = WaitForReadAccess (HandleArray); if (status < 0) { RemoveServer (serverId); return -1; } len = *Length; // // Test for buffer overflow...we don't like to encourage this! // if (len > replyMax) { delete[] replyBuffer; replyBuffer = new unsigned char [len]; replyMax = len; } // // Test for continuation // if (*Type == RGBLOCKINGSEND) { // // No continuation needed // memcpy (replyBuffer, DataBegin, len); return 0; } // // Need continuation // Boolean Loop = TRUE; unsigned char* CurrentOutputPointer = replyBuffer; int WriteSize = BufferSize; int LeftToWrite = len; Boolean Wait = FALSE; while (Loop) { if (Wait) { status = WaitForReadAccess (HandleArray); // wait for continuation clearance if (status < 0) return status; } Wait = TRUE; memcpy (CurrentOutputPointer, DataBegin, WriteSize); CurrentOutputPointer += BufferSize; LeftToWrite -= BufferSize; HandleArray [1] = ContinuationHandle; if ((LeftToWrite <= 0) || (*Type == RGBLOCKINGSEND)) Loop = FALSE; else { SetEvent (OKToWriteHandle); if (LeftToWrite <= BufferSize) WriteSize = LeftToWrite; } } // end of while loop return 0; }
void NetPrefsServerView::MessageReceived (BMessage * msg) { switch (msg->what) { case M_SERVER_ITEM_SELECTED: { BRow *row (fServerList->CurrentSelection ()); if (row) { fEditButton->SetEnabled (true); fRemoveButton->SetEnabled (true); } else { fEditButton->SetEnabled (false); fRemoveButton->SetEnabled (false); } } break; case M_SERVER_ADD_ITEM: { BMessenger msgr (fEntryWin); if (msgr.IsValid ()) fEntryWin->Activate (); else { fEntryWin = new ServerEntryWindow (this, new BMessage (M_SERVER_RECV_DATA), NULL, 0); fEntryWin->Show (); } } break; case M_SERVER_EDIT_ITEM: { BMessenger msgr (fEntryWin); if (msgr.IsValid ()) fEntryWin->Activate (); else { BRow *row (fServerList->CurrentSelection ()); if (!row) break; int32 count (0); ssize_t size (0); type_code type; fActiveNetwork->GetInfo ("server", &type, &count); const ServerData *compData; for (int32 i = 0; i < count; i++) { fActiveNetwork->FindData ("server", B_RAW_TYPE, i, reinterpret_cast < const void **>(&compData), &size); if (!strcmp (compData->serverName, ((BStringField *) row->GetField (1))->String ())) break; } BMessage *invoke (new BMessage (M_SERVER_RECV_DATA)); invoke->AddBool ("edit", true); fEntryWin = new ServerEntryWindow (this, invoke, compData, size); fEntryWin->Show (); } } break; case M_SERVER_REMOVE_ITEM: { RemoveServer (); fNetWin.SendMessage (M_SERVER_DATA_CHANGED); } break; case M_SERVER_RECV_DATA: { const ServerData *data; ssize_t size; Window ()->DisableUpdates (); msg->FindData ("server", B_RAW_TYPE, reinterpret_cast < const void **>(&data), &size); if (msg->HasBool ("edit")) RemoveServer (); UpdateNetworkData (data); AddServer (data); Window ()->EnableUpdates (); fNetWin.SendMessage (M_SERVER_DATA_CHANGED); } break; default: BView::MessageReceived (msg); break; } }
void CServerList::ServerStats() { uint32 tNow = ::GetTickCount(); if (theApp->IsConnectedED2K() && m_servers.size() > 0) { CServer* ping_server = GetNextStatServer(); CServer* test = ping_server; if (!ping_server) { return; } while (ping_server->GetLastPingedTime() && (tNow - ping_server->GetLastPingedTime()) < UDPSERVSTATREASKTIME) { ping_server = GetNextStatServer(); if (ping_server == test) { return; } } if (ping_server->GetFailedCount() >= thePrefs::GetDeadserverRetries() && thePrefs::DeadServer() && !ping_server->IsStaticMember()) { RemoveServer(ping_server); return; } srand((unsigned)time(NULL)); ping_server->SetRealLastPingedTime(tNow); // this is not used to calcualte the next ping, but only to ensure a minimum delay for premature pings if (!ping_server->GetCryptPingReplyPending() && (!ping_server->GetLastPingedTime() || (tNow - ping_server->GetLastPingedTime()) >= UDPSERVSTATREASKTIME) && theApp->GetPublicIP() && thePrefs::IsServerCryptLayerUDPEnabled()) { // We try a obfsucation ping first and wait 20 seconds for an answer // if it doesn't get responsed, we don't count it as error but continue with a normal ping ping_server->SetCryptPingReplyPending(true); uint32 nPacketLen = 4 + (uint8)(rand() % 16); // max padding 16 bytes CScopedArray<byte> pRawPacket(nPacketLen); uint32 dwChallenge = (rand() << 17) | (rand() << 2) | (rand() & 0x03); if (dwChallenge == 0) { dwChallenge++; } memcpy(pRawPacket.get(), &dwChallenge, sizeof(uint32)); for (uint32 i = 4; i < nPacketLen; i++) { // fillng up the remaining bytes with random data pRawPacket[i] = (uint8)rand(); } ping_server->SetChallenge(dwChallenge); ping_server->SetLastPinged(tNow); ping_server->SetLastPingedTime((tNow - (uint32)UDPSERVSTATREASKTIME) + 20); // give it 20 seconds to respond AddDebugLogLineN(logServerUDP, CFormat(wxT(">> Sending OP__GlobServStatReq (obfuscated) to server %s:%u")) % ping_server->GetAddress() % ping_server->GetPort()); CPacket* packet = new CPacket(pRawPacket[1], nPacketLen - 2, pRawPacket[0]); packet->CopyToDataBuffer(0, pRawPacket.get() + 2, nPacketLen - 2); theStats::AddUpOverheadServer(packet->GetPacketSize()); theApp->serverconnect->SendUDPPacket(packet, ping_server, true, true /*raw packet*/, 12 /* Port offset is 12 for obfuscated encryption*/); } else if (ping_server->GetCryptPingReplyPending() || theApp->GetPublicIP() == 0 || !thePrefs::IsServerCryptLayerUDPEnabled()){ // our obfsucation ping request was not answered, so probably the server doesn'T supports obfuscation // continue with a normal request if (ping_server->GetCryptPingReplyPending() && thePrefs::IsServerCryptLayerUDPEnabled()) { AddDebugLogLineN(logServerUDP, wxT("CryptPing failed for server ") + ping_server->GetListName()); } else if (thePrefs::IsServerCryptLayerUDPEnabled()) { AddDebugLogLineN(logServerUDP, wxT("CryptPing skipped because our public IP is unknown for server ") + ping_server->GetListName()); } ping_server->SetCryptPingReplyPending(false); CPacket* packet = new CPacket(OP_GLOBSERVSTATREQ, 4, OP_EDONKEYPROT); uint32 challenge = 0x55AA0000 + (uint16)rand(); ping_server->SetChallenge(challenge); packet->CopyUInt32ToDataBuffer(challenge); ping_server->SetLastPinged(tNow); ping_server->SetLastPingedTime(tNow - (rand() % HR2S(1))); ping_server->AddFailedCount(); Notify_ServerRefresh(ping_server); theStats::AddUpOverheadServer(packet->GetPacketSize()); theApp->serverconnect->SendUDPPacket(packet, ping_server, true); } else { wxFAIL; } } }
void CChatControl::Timer() { int ChatConnects = 0; if(m_TryUltraCache > 0) m_TryUltraCache--; if(m_ServerList.size() == 0) m_UltraCacheMode = false; // Manage connected chat servers std::vector<CChatServer*>::iterator itServer; for(itServer = m_ServerList.begin(); itServer != m_ServerList.end(); itServer++) { if((*itServer)->m_Status == SOCK_CONNECTED) { ChatConnects++; } else { if((*itServer)->m_SecsDead > 5) { RemoveServer(*itServer); itServer--; } else (*itServer)->m_SecsDead++; } } // Send a connect request if we're connected and in the cache channel if(ChatConnects) if(m_UltraCacheMode) { if(m_SecsRequest > 50) m_SecsRequest = SendRequest() ? 0 : 50; else m_SecsRequest++; } // Chat window open if(m_pDoc->m_pViewChat) { if(m_AutoConnect) { bool ChatConnect = false; for(int i = 0; i < m_ServerList.size(); i++) if(m_ServerList[i]->m_Host == "irc.freenode.net") ChatConnect = true; if(!ChatConnect) GetConnect(); } } // Chat window not open else if(m_AutoConnect) { if(ChatConnects) { if(!m_UltraCacheMode && m_TryUltraCache == 0) if(m_autNetwork->ClientMode() == CLIENT_LEAF || m_autPrefs->GetMinConnects() != -1 && m_autNetwork->GetNormalConnectedCount() >= m_autPrefs->GetMinConnects()) RemoveServer( m_ServerList[0] ); } else { if(m_autNetwork->GetNormalConnectedCount() == 0) GetConnect(); m_UltraCacheMode = false; m_TryUltraCache = 0; } } // Clean Chat Sockets std::vector<CChatServer*>::iterator itChat; for(itChat = m_ServerList.begin(); itChat != m_ServerList.end(); itChat++) if((*itChat)->m_Status == SOCK_CLOSED) { delete *itChat; m_ServerList.erase(itChat); itChat--; } // Remove old ident connects std::vector<CChatIdentd*>::iterator itIdent; for(itIdent = m_IdentdList.begin(); itIdent != m_IdentdList.end(); itIdent++) { (*itIdent)->m_SecsAlive++; if((*itIdent)->m_SecsAlive >= 10) { delete *itIdent; m_IdentdList.erase(itIdent); itIdent--; } } }