Server::Server(const QString &file, QObject *parent) : QTcpServer(parent), m_file(file) { setMaxPendingConnections(1); // No DoS attack ((: m_file.open(QIODevice::ReadOnly); m_map = m_file.map(0,m_file.size()); m_blocks = m_file.size()/MAX_DATA_SIZE; m_lastblock = m_file.size() - (MAX_DATA_SIZE * m_blocks); connect(this,SIGNAL(newConnection()), this, SLOT(createNewClient())); }
void EchoServer::start() { if (serverStatus) { return; } if ( !server->listen(QHostAddress::Any, port) ) { qDebug() << "Server could not start!"; return; } qDebug() << "Server started!"; connect(server, SIGNAL(newConnection()),this,SLOT(createNewClient())); serverStatus = true; }
int TCPServer::acceptClientConnection() { int nClients = 0; while(1) { struct sockaddr_in client_address; unsigned int sockaddr_in_len = (sizeof(struct sockaddr_in)); int clientId = accept4(descriptor, (struct sockaddr *) &client_address, &sockaddr_in_len, SOCK_CLOEXEC); if( clientId > 0 ) createNewClient( clientId ); else break; nClients++; } return nClients; }