void EspolBoxServer::incomingConnection(qintptr scktID) { qDebug() << scktID << " Connecting..."; ServerThread *thread = new ServerThread(scktID, this); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start(); }
void FaceView::OnSocketEvent(wxSocketEvent& event) { wxSocketBase *sock = event.GetSocket(); static int test = 0; // Now we process the event switch(event.GetSocketEvent()) { case wxSOCKET_INPUT: { wxString msg; msg.sprintf(_T("input id: %d"), ++test); sock->SaveState(); // sock->SetNotify(wxSOCKET_LOST_FLAG); wxLogStatus(msg, 0); ServerThread* pThread = new ServerThread(/*this, */m_pApp, sock); pThread->Create(); pThread->Run(); sock->RestoreState(); //sock->SetNotify(wxSOCKET_LOST_FLAG | wxSOCKET_INPUT_FLAG); break; } case wxSOCKET_LOST: { if(!m_SocketIdHash.erase(sock)) { //sth weird going on, LOG IT! } sock->Destroy(); wxLogStatus(wxT("Remote client connection closed.")); break; } default: ; } }
int main(int argc, char *argv[]) { if (argc < 2) //The server key name must be passed return -1; QCoreApplication a(argc, argv); Tiio::defineStd(); initImageIo(); QString srvName(QString::fromUtf8(argv[1])); QString mainSrvName(srvName + "_main"); QLocalServer::removeServer(srvName); QLocalServer::removeServer(mainSrvName); //Start a separate thread to host most of the event processing ServerThread *srvThread = new ServerThread(srvName); srvThread->start(); //Start a server on the main thread too - this one to host //commands that need to be explicitly performed on the main thread tipc::Server server; mov_io::addParsers(&server); _3gp_io::addParsers(&server); #ifdef MACOSX font_io::addParsers(&server); #endif //Start listening on supplied key bool ok = server.listen(srvName + "_main"); a.exec(); }
void Server::incomingConnection( int descriptor ) { ServerThread *thread = new ServerThread( descriptor, this ); connect( thread, SIGNAL(finished()), thread, SLOT(deleteLater()) ); thread->start(); }
void Server::incomingConnection(int socketID) { ServerThread *serverThread = new ServerThread(socketID, management, this); //connect(serverThread, SIGNAL(finished()), serverThread, SLOT(deleteLater())); serverThread->start(); }
void NetServer::incomingConnection(int socketDescriptor) { ServerThread* thread = new ServerThread(socketDescriptor); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); connect(thread, SIGNAL(peerConnected(PeerInfo*)), this, SLOT(peerConnected_slot(PeerInfo*))); connect(thread, SIGNAL(peerDisconnected(PeerInfo*)), this, SLOT(peerDisconnected_slot(PeerInfo*))); connect(thread, SIGNAL(incomingMessage(PeerInfo*,QByteArray)), this, SLOT(incomingMessage_slot(PeerInfo*,QByteArray))); thread->start(); }
/** * Handle incoming connections. This is called when a connection is * requested, it spawns a new thread and continues. * * @version * - JR Lewis 2012.02.07 * - Initial version. */ void Server::incomingConnection(int socketDescriptor) { ServerThread* pThread = new ServerThread( socketDescriptor , messages , *this->response_mechanism , this); bool r = QObject::connect( this , SIGNAL(Destroy()) , pThread , SLOT(OnDestroy())); assert(r); pThread->Start(); }
// actual function run in listener on server threads void* server_thread_fn(void* arg) { ServerThread* child = (ServerThread*)arg; #ifndef WIN32 // First, let's block all signals Thread::mask_all_signals(); #endif // Run the child until it exits. child->run(); // Now we can clean up and exit the thread. delete child; return NULL; }
/*新连接进入处理函数*/ void Server::incomingConnection(int socketDescriptor) { ServerThread *thread = new ServerThread(socketDescriptor,this); /*当线程完成执行时,自动销毁*/ connect(thread,SIGNAL(finished()),thread,SLOT(deleteLater())); /*连接消息到达信号*/ connect(thread,SIGNAL(messageArrive(int,qint32,QVariant)), this,SIGNAL(messageArrive(int,qint32,QVariant))); /*连接消息发送信号*/ connect(this,SIGNAL(sendData(int,qint32,QVariant)), thread,SIGNAL(sendData(int,qint32,QVariant)),Qt::DirectConnection); /*连接客户端断开信号,参数为套接字描述符, 在clientDisconnect函数中会将拥有该描述符的线程从threadList中移除*/ connect(thread, SIGNAL(disconnect(int)), this, SLOT(clientDisconnect(int)),Qt::QueuedConnection); thread->start();//线程启动 _threadList.append(thread); }
void TcpServer::incomingConnection(qintptr socketDescriptor) { // We have a new connection DEBUG() << socketDescriptor << " Connecting..."; // Every new connection will be run in a newly created thread ServerThread *thread = new ServerThread(socketDescriptor, this); m_thread_set.insert(thread); // connect signal/slot // once a thread is not needed, it will be beleted later connect(thread, &QThread::finished, [=](){ DEBUG() << "thread finished"; DEBUG() << "current connections " << m_connections_count; thread->deleteLater(); m_connections_count--; m_thread_set.remove(thread); DEBUG() << "Threads left in queue" << m_thread_set.count(); if(m_connections_count < m_max_connections) { if(!m_thread_set.isEmpty()) m_next_thread = m_thread_set.values().first(); else m_next_thread = NULL; } }); thread->start(); if(m_next_thread == NULL || m_connections_count < m_max_connections) { m_next_thread = thread; } while(m_next_thread != thread) { DEBUG() << "Sleepping"; thread->msleep(100); } m_connections_count++; }
int main(int argc, char *argv[]) { QApplication a(argc, argv); a.setOrganizationName("Batty Bovine Productions, LLC"); a.setOrganizationDomain("animerenderfarm.battybovine.com"); a.setApplicationName("Anime Renderfarm"); a.setApplicationVersion("0.1.1"); // Handle command line arguments if(cmdArgs(a.arguments())) { // If the arguments indicate we want to run in server mode, do so ServerThread *st = new ServerThread(); st->start(); } else { // Otherwise, start the main window of the GUI interface AnimeRenderfarm w; w.show(); return a.exec(); } }
inline Key get_metadata_key(const ServerThread& st, unsigned tier_id, unsigned thread_num, MetadataType type) { std::string suffix; switch (type) { case MetadataType::server_stats: suffix = "stats"; break; case MetadataType::key_access: suffix = "access"; break; case MetadataType::key_size: suffix = "size"; break; default: return ""; // this should never happen; see note below about // MetadataType::replication } return kMetadataIdentifier + kMetadataDelimiter + st.get_ip() + kMetadataDelimiter + std::to_string(thread_num) + kMetadataDelimiter + "tier" + std::to_string(tier_id) + kMetadataDelimiter + suffix; }
ThreadManager& ServerThreadManager::start(Runnable *runnable) { ServerThread *thread = new ServerThread(this, runnable, newJobId()); thread->start(); return *this; }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QString serverAddr = ""; int serverPort = 0; ServerThread *server; StartupPage page; page.show(); page.exec(); if (page.exit) return 0; var isServer = page.isServer; qDebug() << (isServer ? "server" : "client"); if (isServer) { int timeLimit = defaultTimeLimit; QString initStatus = defaultInitStatus; bool whiteFirst = false; CustomBoard board; board.show(); board.exec(); initStatus = board.res; timeLimit = board.tl; whiteFirst = board.whiteFirst; ServerSettings settings; settings.show(); settings.exec(); serverPort = settings.portSelected; if (!~serverPort) return 0; server = new ServerThread(serverPort, timeLimit, initStatus, whiteFirst); server->start(); server->moveToThread(server); client.connectToServer(getCurrentInterfaceAddress().ip(), serverPort); Waiting waitingPage; QObject::connect(server, SIGNAL(onClientsConnected()), &waitingPage, SLOT(close())); waitingPage.show(); waitingPage.exec(); serverAddr = getCurrentInterfaceAddress().ip().toString(); } else { ConnectToServer conn; conn.show(); conn.exec(); serverAddr = conn.serverIp; serverPort = conn.serverPort; if (!~serverPort) return 0; client.connectToServer(QHostAddress(serverAddr), serverPort); Waiting waitingPage; QObject::connect(&client, SIGNAL(onConnected()), &waitingPage, SLOT(close())); waitingPage.show(); waitingPage.exec(); } MainWindow mw(&client); mw.show(); int rv = app.exec(); client.sock->disconnectFromHost(); return rv; }