int main(int argc, char *argv[]) { int cliSock; if (argc < 2) exitError("ERROR: port number not provided\n",1); srvSock = tcpListen(argv[1]); signal(SIGINT, sig_int); while (1) { cliSock = accept(srvSock, NULL, NULL); if (cliSock == -1) exitError("ERROR: could not accept incoming connection\n", 1); handleHttpRequest(cliSock); closeWriteSock(cliSock); } }
void * thread_start(void * args) { int cliSock; int tNum = *((int*) args); free(args); pthread_detach(pthread_self()); printf("Pre-created worker thread %d\n", tNum); while(1){ pthread_mutex_lock(&cliMutex); while (cliGet == cliPut) pthread_cond_wait(&cliCond, &cliMutex); cliSock = cliSocks[cliGet]; /* connected socket to service */ if (++cliGet == MAX_CLI) cliGet = 0; pthread_mutex_unlock(&cliMutex); threads[tNum].nConn++; handleHttpRequest(cliSock); closeWriteSock(cliSock); } return 0; }
void HTTPCallbackTcpConnection::start() { httpMessage.clear(); handleHttpRequest(error_code(), 0); }