void Server::onAccept( ) { TRACE_ENTERLEAVE( ); // // accept new connection and add it to connection thread // sys::Socket* socket = m_socket.accept( ); if ( !socket ) { TRACE_ERROR( "accept failed, error %d", sys::Socket::getLastError( ) ); return; } // // get first connection thread // ConnectionThread* thread; { sys::LockEnterLeave lock( m_lock ); if ( m_connectionThreads.size() < m_connectionThreadCount ) { thread = new ConnectionThread( *this ); } else { thread = m_connectionThreads.front( ); m_connectionThreads.pop_front( ); } } // // create new connection and assign it to connection thread. it mantains referencre count and will delete itself when no longer referenced // Connection* connection = newConnection( *thread, socket ); if ( m_storeConnections ) { thread->add( connection ); } // // enable events processing on this connection // connection->enable( ); // // add connection thread to back // { sys::LockEnterLeave lock( m_lock ); m_connectionThreads.push_back( thread ); } }
void Server::incomingConnection(int socketDescriptor) { qDebug() << socketDescriptor << "Connecting..."; ConnectionThread *clientThread = new ConnectionThread(socketDescriptor, this); connect(clientThread, SIGNAL(finished()), clientThread, SLOT(deleteLater())); clientThread->start(); }
//! Receives the connections and creates a new ConnectionThread for each client. void ConnectionReceiver::run() { while(running) { if(tcpServer->waitForNewConnection(-1, NULL)) { if(!accepting) { QTcpSocket* s = tcpServer->nextPendingConnection(); s->disconnectFromHost(); delete s; continue; } qDebug() << "Clientconnected"; ConnectionThread* connection = new ConnectionThread(tcpServer->nextPendingConnection(), server); connection->start(); } } }
void *SendVideo( void *argc ) { int channel=0, port=0; int *tmp_1, *tmp_2; unsigned char *infor = (unsigned char *) argc; tmp_1 = (int *) infor; channel = *tmp_1; tmp_2 = (int *) (infor+4); port = *tmp_2; fprintf( stderr, "Go Multi-port\n" ); printf( "----->%d, %d<-----\n", channel, port ); ConnectionThread *ptr; ptr = new ConnectionThread; // pthread_mutex_lock( &mutex ); if( channel == 1 ) { ptr->setArbiter(0); //thread_table.push_back( ptr ); } else if( channel == 2 ) { ptr->setArbiter(1); //thread_table_1.push_back( ptr ); } else { printf( "shit: %d\n", channel ); } // pthread_mutex_unlock( &mutex ); ptr->RunThread( port ); }
void Server::incomingConnection(int socketDescriptor) { ConnectionThread * thread = new ConnectionThread(logger, smsManager, socketDescriptor, this); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start(); }
void TimeServer::incomingConnection(int socketDescriptor) { ConnectionThread *thread = new ConnectionThread(socketDescriptor); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start(); }