void PvdImpl::disconnect() { if(mProfileZone) { mProfileZoneManager->removeProfileZoneHandler(*mProfileClient); mProfileZoneManager->removeProfileZone( *mProfileZone ); mProfileZone->release(); mProfileZone=NULL; removeClient(mProfileClient); } if(mIsConnected) { for(uint32_t i = 0; i < mPvdClients.size(); i++) mPvdClients[i]->onPvdDisconnected(); if(mMemClient) { removeClient(mMemClient); PvdMemClient* tmp = mMemClient; //avoid tracking deallocation itsself mMemClient = NULL; PVD_DELETE(tmp); } mSharedMetaProvider->release(); mPvdTransport->disconnect(); mObjectRegistrar.clear(); mIsConnected = false; } }
void ServerVideoManager::send_wrapper(const char FAR * buf,int len,int client) { if(client!=-1) { //Only one client if(sv[client] && sv[client]!=INVALID_SOCKET) { int n=send(sv[client],buf,len,NULL); if(n==0 || n==SOCKET_ERROR) { removeClient(client); } } }else{ // All the clients for(int i=0; i<MAX_NUM_USERS; i++) { if(sv[i] && sv[i]!=INVALID_SOCKET) { int n=send(sv[i],buf,len,NULL); if(n==0 || n==SOCKET_ERROR) { removeClient(i); } } } } }
void CSSCrossfadeValue::loadSubimages(CachedResourceLoader& cachedResourceLoader, const ResourceLoaderOptions& options) { auto oldCachedFromImage = m_cachedFromImage; auto oldCachedToImage = m_cachedToImage; m_cachedFromImage = CSSImageGeneratorValue::cachedImageForCSSValue(m_fromValue, cachedResourceLoader, options); m_cachedToImage = CSSImageGeneratorValue::cachedImageForCSSValue(m_toValue, cachedResourceLoader, options); if (m_cachedFromImage != oldCachedFromImage) { if (oldCachedFromImage) oldCachedFromImage->removeClient(m_subimageObserver); if (m_cachedFromImage) m_cachedFromImage->addClient(m_subimageObserver); } if (m_cachedToImage != oldCachedToImage) { if (oldCachedToImage) oldCachedToImage->removeClient(m_subimageObserver); if (m_cachedToImage) m_cachedToImage->addClient(m_subimageObserver); } // FIXME: Unclear why this boolean adds any value; for now keeping it around to avoid changing semantics. m_subimagesAreReady = true; }
void registerHandle(struct ClientNode *client) { // HEADER[kChatHeaderSize] handleLen[1] handle[handleLen] uint8_t *buf = (uint8_t *)client->packetData; uint8_t handleLen = *(buf + kChatHeaderSize); // Make sure we have received a buffer big enough to // contain the handle if (client->packetLength < (kChatHeaderSize + handleLen + 1)) { respondToClient(client, FLAG_INIT_ERR, NULL, 0); removeClient(client); return; } char *clientHandle = malloc(handleLen+1); if (clientHandle == NULL) { perror("registerHandle:malloc"); exit(1); } memcpy(clientHandle, buf + kChatHeaderSize + 1, handleLen); clientHandle[handleLen] = '\0'; // Make sure this handle isn't already registered if (clientNamed(clientHandle) && (clientNamed(clientHandle) != client)) { respondToClient(client, FLAG_INIT_ERR, NULL, 0); removeClient(client); return; } client->clientName = clientHandle; respondToClient(client, FLAG_INIT_ACK, NULL, 0); }
void Connection::Server::update() { std::lock_guard<std::recursive_mutex> lock(*this); if (state != SETUP) { if (clients.empty()) { state = END; return; } } if (state == SETUP && !listeners.empty()) { try { metaserver.sendGame(*this); } catch (...) { // FIXME: Something went wrong, log it and tell the user! } } for (ListenerContainerType::iterator i = listeners.begin(); i != listeners.end();) { ListenerContainerType::iterator j = i++; Listener& listener = **j; if (!listener.update(*this)) { listeners.erase(j); } } for (ClientInfoContainerType::iterator i = clients.begin(); i != clients.end();) { ClientInfoContainerType::iterator j = i++; Client& client = dynamic_cast<Client&>(*j->second); EndPoint& endPoint = *client.connection; std::string data; while (true) { try { if (!endPoint.receivePacket(data)) { break; } } catch (...) { removeClient(j->first); break; } if (!data.empty()) { if (!handlePacket(client, data)) { removeClient(j->first); break; } } } } if (state == PLAY) { game->runUntil(clock.getTime(), std::bind(&Server::sendMessage, this, std::placeholders::_1)); // PING Game::Message msg; msg.timestamp = game->getTime(); sendMessage(msg); } }
int main(int argc, char *argv[]){ struct sockaddr_in cliaddr; char buf[MAXLINE+1]; int i, j, nbyte, accp_sock, addrlen = sizeof(struct sockaddr_in); fd_set read_fds; if(argc != 2) { printf("사용법 : %s port\n", argv[0]); exit(0); } listen_sock = tcp_listen(INADDR_ANY, atoi(argv[1]), 5); while(1){ FD_ZERO(&read_fds); FD_SET(listen_sock, &read_fds); for(i=0; i<num_chat; i++) FD_SET(clisock_list[i], &read_fds); maxfdp1 = getmax() + 1; puts("wait for client"); if(select(maxfdp1, &read_fds, NULL, NULL, NULL)<0) errquit("select fail"); if(FD_ISSET(listen_sock, &read_fds)){ accp_sock=accept(listen_sock, (struct sockaddr*)&cliaddr, &addrlen); if(accp_sock == -1) errquit("accept fail"); addClient(accp_sock, &cliaddr); send(accp_sock, START_STRING, strlen(START_STRING), 0); printf("%d번째 사용자 추가.\n", num_chat); } for(i=0; i<num_chat; i++){ if(FD_ISSET(clisock_list[i], &read_fds)){ nbyte = recv(clisock_list[i], buf, MAXLINE, 0); if(nbyte <=0){ removeClient(i); continue; } buf[nbyte] = 0; if(strstr(buf, EXIT_STRING) != NULL) { removeClient(i); continue; } for(j=0; j<num_chat; j++) send(clisock_list[j], buf, nbyte, 0); printf("%s\n", buf); } } } return 0; }
void Connection::Server::sendPacket(Client& client, const std::string& data) { try { client.connection->sendPacket(data); } catch (...) { removeClient(client.id); } }
void FTPServer::clientMessage(MessageType type, int sessionID, QString message) { QString id = QString::number(sessionID); switch(type) { case DataReceived: emit logMessage(id + " Data recived: " + message.trimmed()); break; case DataSent: emit logMessage(id + " Data sent: " + message.trimmed()); break; case Error: emit logMessage(id + " Error: " + message.trimmed()); break; case Connected: { FTPClient *client = qobject_cast<FTPClient*>(sender()); if(client) addClient(sessionID, client); break; } case Disconnected: removeClient(sessionID); break; default: emit logMessage(id + " " + message.trimmed()); } }
void MainServeur::run() { m_Client = new QTcpSocket; if(!m_Client->setSocketDescriptor(m_Handle)) { emit message(tr("Error : When setting Socket Descriptor : %1").arg(QString::number(m_Handle))); return; } while((threadRunning) || (!errorFatal)) { if(m_Client->waitForReadyRead(5000)) { if(m_Authentification->State() == AuthentificationSystem::Accepted) emit message(tr("Données reçues depuis %1").arg(m_Authentification->GetUserName())); else emit message(tr("Données reçues depuis un inconnu.")); ProcessData(); } m_Client->waitForBytesWritten(); msleep(750); if(m_Client->state() == QTcpSocket::UnconnectedState) { if(m_Authentification->State() == AuthentificationSystem::Accepted) emit removeClient(m_Authentification->GetUserName(), m_Authentification->GetClasse()); break; } } }
void Servatrice_GameServer::incomingConnection(qintptr socketDescriptor) #endif { // Determine connection pool with smallest client count int minClientCount = -1; int poolIndex = -1; QStringList debugStr; for (int i = 0; i < connectionPools.size(); ++i) { const int clientCount = connectionPools[i]->getClientCount(); if ((poolIndex == -1) || (clientCount < minClientCount)) { minClientCount = clientCount; poolIndex = i; } debugStr.append(QString::number(clientCount)); } qDebug() << "Pool utilisation:" << debugStr; Servatrice_ConnectionPool *pool = connectionPools[poolIndex]; ServerSocketInterface *ssi = new ServerSocketInterface(server, pool->getDatabaseInterface()); ssi->moveToThread(pool->thread()); pool->addClient(); connect(ssi, SIGNAL(destroyed()), pool, SLOT(removeClient())); QMetaObject::invokeMethod(ssi, "initConnection", Qt::QueuedConnection, Q_ARG(int, socketDescriptor)); }
void* checkIfClientIsConnected(void* clients_void){ CheckClient* cc = (CheckClient*) clients_void; ListClient* clients = cc->clients; while(true){ ItemList client = clients->firstItem; while(client != NULL){ ClientNetwork* cn = client->client; cn->nbTry++; if(cn->nbTry == NB_MAX_TRY){ printf("Client %s disconnected\n", cn->name); client = client->next; savePlayer(*getPlayerByName(cn->players, cn->name)); removeClient(clients, cn); removePlayerByName(cn->players, cn->name); } else{ #ifdef DEBUG //printf("nbTry : %d\n", cn->nbTry); #endif client = client->next; } } getFileFromMap(cc->map); sleep(1); } pthread_exit(NULL); }
void mainWindow::makeConnections() { QObject::connect(actionAbout, SIGNAL( triggered() ), this, SLOT( show_aboutDialog() ) ); QObject::connect(actionPreferences, SIGNAL( triggered() ), this, SLOT( show_preferences() ) ); QObject::connect(actionStart, SIGNAL( triggered() ), this, SLOT( startFolding() ) ); QObject::connect(actionStop, SIGNAL( triggered() ), this, SLOT( stopFolding() ) ); QObject::connect(actionHomepage, SIGNAL( triggered() ), this, SLOT( loadHomepage() ) ); QObject::connect(actionSourceForge, SIGNAL( triggered() ), this, SLOT( loadSourceForge() ) ); QObject::connect(actionFoldingWebsite, SIGNAL( triggered() ), this, SLOT( loadFoldingWebsite() ) ); QObject::connect(actionFoldingForum, SIGNAL( triggered() ), this, SLOT( loadFoldingForum() ) ); QObject::connect(actionContact, SIGNAL( triggered() ), this, SLOT( contactAuthor() ) ); QObject::connect(actionAddClient, SIGNAL( triggered() ), this, SLOT( addClient() ) ); QObject::connect(actionRemoveClient, SIGNAL( triggered() ), this, SLOT( removeClient() ) ); QObject::connect(actionSaveConfig, SIGNAL( triggered() ), this, SLOT( saveConfig() ) ); QObject::connect(actionPersonalStats, SIGNAL( triggered() ), this, SLOT( reloadPersonalStats() ) ); QObject::connect(actionTeamStats, SIGNAL( triggered() ), this, SLOT( reloadTeamStats() ) ); QObject::connect(actionMoleculeViewer, SIGNAL( triggered() ), this, SLOT( showMolecule() ) ); QObject::connect(actionExit, SIGNAL(triggered()), this, SLOT(checkExit())); QObject::connect(clients->table, SIGNAL( cellClicked( int, int) ), this, SLOT( showInfo())); Reloader = new QTimer(this); connect(Reloader, SIGNAL(timeout()), this, SLOT(reloadClients())); Reloader->start(60000); }
void Server::incomingConnection(int socketDescriptor) { qDebug() << "Incoming connection"; socket = new QTcpSocket(this); socket->setSocketDescriptor(socketDescriptor); connect(socket, SIGNAL(readyRead()), this, SLOT(processClient())); connect(socket, SIGNAL(disconnected()), this, SLOT(removeClient())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketError(QAbstractSocket::SocketError))); }
void handleClient(struct ClientNode *client) { ssize_t bytesRcvd; uint8_t *buf = malloc(MAX_PACKET_SIZE); if (buf == NULL) { perror("handleClient:malloc"); return; } if ((bytesRcvd = recv(client->clientSocket, buf, MAX_PACKET_SIZE-1, 0)) < 0) { perror("handleClient:recv"); free(buf); return; } // Check for a shutdown if (bytesRcvd == 0) { removeClient(client); } // Parse the buffer else { client->packetLength = bytesRcvd; client->packetData = (struct ChatHeader *)buf; // make sure the checksum is correct before parsing the packets if (in_cksum((uint16_t *)client->packetData, client->packetLength) == 0) { // Put the packet header fields in host order switch (client->packetData->flag) { case FLAG_INIT_REQ: registerHandle(client); break; case FLAG_MSG_REQ: case FLAG_MSG_ACK: forwardMessage(client); break; case FLAG_EXIT_REQ: clientExit(client); break; case FLAG_LIST_REQ: getClientCount(client); break; case FLAG_HNDL_REQ: clientNameRequest(client); break; case FLAG_INIT_ACK: case FLAG_INIT_ERR: case FLAG_MSG_ERR: case FLAG_EXIT_ACK: case FLAG_LIST_RESP: case FLAG_HNDL_RESP: default: break; } } client->packetData = NULL; client->packetLength = 0; } free(buf); }
void Servatrice_WebsocketGameServer::onNewConnection() { Servatrice_ConnectionPool *pool = findLeastUsedConnectionPool(); WebsocketServerSocketInterface *ssi = new WebsocketServerSocketInterface(server, pool->getDatabaseInterface()); // ssi->moveToThread(pool->thread()); pool->addClient(); connect(ssi, SIGNAL(destroyed()), pool, SLOT(removeClient())); QMetaObject::invokeMethod(ssi, "initConnection", Qt::QueuedConnection, Q_ARG(void *, nextPendingConnection())); }
void Servatrice_GameServer::incomingConnection(qintptr socketDescriptor) { Servatrice_ConnectionPool *pool = findLeastUsedConnectionPool(); TcpServerSocketInterface *ssi = new TcpServerSocketInterface(server, pool->getDatabaseInterface()); ssi->moveToThread(pool->thread()); pool->addClient(); connect(ssi, SIGNAL(destroyed()), pool, SLOT(removeClient())); QMetaObject::invokeMethod(ssi, "initConnection", Qt::QueuedConnection, Q_ARG(int, socketDescriptor)); }
JrServer::~JrServer() { _Info("Closing server."); setInterface(nullptr); auto devices = d->clients.keys(); for (auto dev : devices) { dev->close(); removeClient(dev); } delete d->transport; delete d; }
void TorrentServer::processInfoHash(const QByteArray &infoHash) { PeerWireClient *peer = qobject_cast<PeerWireClient *>(sender()); foreach (TorrentClient *client, clients) { if (client->state() >= TorrentClient::Searching && client->infoHash() == infoHash) { peer->disconnect(peer, 0, this, 0); client->setupIncomingConnection(peer); return; } } removeClient(); }
bool ProcessServer::validateClient( dword client ) { AutoLock lock( &m_Lock ); Hash<dword,bool>::Iterator find = m_ClientValid.find( client ); if ( find.valid() && *find ) return true; LOG_STATUS( "ProcessServer", CharString().format("Failed validation, client = %d (%s)", client, clientAddress(client)) ); removeClient( client ); return false; }
void ServerBase::sendEvents(EventMap<PlayerID>& events) { for(auto clientQueuePair : events) { auto clientPair = _assignedIDs.find(clientQueuePair.first); if(clientPair == _assignedIDs.end()) { Error("Invalid player ID " << clientQueuePair.first << " found in event map"); continue; } ClientBase* thisClient = clientPair->second; if(!thisClient->sendToClient(clientQueuePair.second)) { Debug("Failed to send data to client"); removeClient(thisClient); } } }
void ClientWidget::chooseLoadData() { int i = socket->getIndexOfLastQuery( qList ); QString str = socket->getData(); socket->closeConnection(); info->showProgressBar( false ); if( i < 0 ) return; //if( str.isEmpty() || str.isNull() ) // return; switch(i) { case 0: { int a = lastRow; loadClients(str); clientTable->SetFocus(a); break; } case 1: { //loadStats(str); break; } case 2: { loadAccounts(str); break; } case 3: { removeClient(str); break; } case 4: { removeClientAnswer(str); break; } case 5: { removeClientAccountAnswer(str); break; } } }
Image* CSSImageGeneratorValue::getImage(RenderObject* renderer, const IntSize& size) { IntSize oldSize = m_clients.get(renderer); if (oldSize != size) { removeClient(renderer); addClient(renderer, size); } // Don't generate an image for empty sizes. if (size.isEmpty()) return 0; // Look up the image in our cache. return m_images.get(size); }
/* Grab commands from clients and process commands * Remove clients if the connection is lost of the client want to quit * * clientManager : ClientManager* - the client manager * readSet : fd_set* - the set of file descriptors that has information to be read * return : void */ void processClientsRequests(ClientManager* clientManager, fd_set* readSet){ char* userInput; Client* clients = clientManager->clients; int i, connectingStatus; int maxCount = clientManager->maxI + 1; for ( i = 0 ; i < maxCount ; i++){ if (clients[i].soc > 0){ if (FD_ISSET(clients[i].soc, readSet)){ connectingStatus = readfromclient(&(clients[i]), &userInput); if (connectingStatus == 0){ printf("Got full command from client %d\n", i); processUserInput(clientManager, userInput, i); removeClient(clientManager, i); } else if (connectingStatus == 1){ // readfromclient returns 1 when client lost connection removeClient(clientManager, i); } // readfromclient returns 2 when a full command is not free(userInput); } } } }
void TorrentServer::incomingConnection(int socketDescriptor) { PeerWireClient *client = new PeerWireClient(ConnectionManager::instance()->clientId(), this); if (client->setSocketDescriptor(socketDescriptor)) { if (ConnectionManager::instance()->canAddConnection() && !clients.isEmpty()) { connect(client, SIGNAL(infoHashReceived(const QByteArray &)), this, SLOT(processInfoHash(const QByteArray &))); connect(client, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(removeClient())); RateController::instance()->addSocket(client); ConnectionManager::instance()->addConnection(client); return; } }
void CachedResource::switchClientsToRevalidatedResource() { ASSERT(m_resourceToRevalidate); ASSERT(m_resourceToRevalidate->inCache()); ASSERT(!inCache()); LOG(ResourceLoading, "CachedResource %p switchClientsToRevalidatedResource %p", this, m_resourceToRevalidate); m_switchingClientsToRevalidatedResource = true; HashSet<CachedResourceHandleBase*>::iterator end = m_handlesToRevalidate.end(); for (HashSet<CachedResourceHandleBase*>::iterator it = m_handlesToRevalidate.begin(); it != end; ++it) { CachedResourceHandleBase* handle = *it; handle->m_resource = m_resourceToRevalidate; m_resourceToRevalidate->registerHandle(handle); --m_handleCount; } ASSERT(!m_handleCount); m_handlesToRevalidate.clear(); Vector<CachedResourceClient*> clientsToMove; HashCountedSet<CachedResourceClient*>::iterator end2 = m_clients.end(); for (HashCountedSet<CachedResourceClient*>::iterator it = m_clients.begin(); it != end2; ++it) { CachedResourceClient* client = it->key; unsigned count = it->value; while (count) { clientsToMove.append(client); --count; } } unsigned moveCount = clientsToMove.size(); for (unsigned n = 0; n < moveCount; ++n) removeClient(clientsToMove[n]); ASSERT(m_clients.isEmpty()); for (unsigned n = 0; n < moveCount; ++n) m_resourceToRevalidate->addClientToSet(clientsToMove[n]); for (unsigned n = 0; n < moveCount; ++n) { // Calling didAddClient may do anything, including trying to cancel revalidation. // Assert that it didn't succeed. ASSERT(m_resourceToRevalidate); // Calling didAddClient for a client may end up removing another client. In that case it won't be in the set anymore. if (m_resourceToRevalidate->m_clients.contains(clientsToMove[n])) m_resourceToRevalidate->didAddClient(clientsToMove[n]); } m_switchingClientsToRevalidatedResource = false; }
void MultiAdapter::shutdown() { AC_TRACE << "MultiAdapter::shutdown"; while (!_allClients.empty()) { (*_allClients.begin())->onDone(CURLE_ABORTED_BY_CALLBACK ); removeClient(*_allClients.begin()); } SocketAdapter::abort(); CURLMcode myStatus = curl_multi_cleanup(_curlMulti); checkCurlStatus(myStatus, PLUS_FILE_LINE); if (timeout_timer) { timeout_timer->cancel(); } AC_TRACE << "MultiAdapter::shutdown done"; };
void GamePair::removeClient(const string &name) { S32 index = -1; const Vector<ClientGame *> *clients = GameManager::getClientGames(); for(S32 i = 0; i < clients->size(); i++) { if(clients->get(i)->getClientInfo() && string(clients->get(i)->getClientInfo()->getName().getString()) == name) { index = i; break; } } ASSERT_TRUE(index >= 0) << "Could not find specified player!"; removeClient(index); }
Image* CSSImageGeneratorValue::getImage(const LayoutObject* layoutObject, const IntSize& size) { LayoutObjectSizeCountMap::iterator it = m_clients.find(layoutObject); if (it != m_clients.end()) { SizeAndCount& sizeCount = it->value; IntSize oldSize = sizeCount.size; if (oldSize != size) { removeClient(layoutObject); addClient(layoutObject, size); } } // Don't generate an image for empty sizes. if (size.isEmpty()) return nullptr; // Look up the image in our cache. return m_images.get(size); }
Image* ImageBySizeCache::getImage(const RenderObject* renderer, const IntSize& size) { RenderObjectSizeCountMap::iterator it = m_clients.find(renderer); ASSERT(it != m_clients.end()); SizeCountPair& sizeCount = it->second; IntSize oldSize = sizeCount.first; if (oldSize != size) { removeClient(renderer); addClient(renderer, size); } // Don't generate an image for empty sizes. if (size.isEmpty()) return 0; // Look up the image in our cache. return m_images.get(size).get(); }
ConnectionManager::ConnectionManager(bool bModal) : ConnectionManagerBase(NULL, "manager", bModal) { SET_WNDPROC("manager") setIcon(Pict("configure")); setButtonsPict(this); setCaption(caption()); lstConnection->setHScrollBarMode(QScrollView::AlwaysOff); lstConnection->header()->hide(); lstConnection->setSorting(1); fill(); connect(btnAdd, SIGNAL(clicked()), this, SLOT(addClient())); connect(btnRemove, SIGNAL(clicked()), this, SLOT(removeClient())); connect(btnUp, SIGNAL(clicked()), this, SLOT(upClient())); connect(btnDown, SIGNAL(clicked()), this, SLOT(downClient())); connect(btnUpdate, SIGNAL(clicked()), this, SLOT(updateClient())); connect(lstConnection, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); m_bModal = bModal; }