int NczThread::Run() { mustbekilled = false; int res = WebThread(); mustbekilled = true; return res; }
//----------------------------------------------------------------------------- // A new Connection is established to newSock. Create a (threaded) Connection // and handle the Request. //----------------------------------------------------------------------------- bool CWebserver::handle_connection(CySocket *newSock) { void *WebThread(void *args); //forward declaration // create arguments TWebserverConnectionArgs *newConn = new TWebserverConnectionArgs; if (!newConn) { dperror("CWebserver TWebserverConnectionArgs error!\n"); return false; } newConn->ySock = newSock; newConn->ySock->handling = true; newConn->WebserverBackref = this; #ifdef Y_CONFIG_FEATURE_THREADING newConn->is_treaded = is_threading; #else newConn->is_treaded = false; #endif int index = -1; #ifdef Y_CONFIG_FEATURE_THREADING if(is_threading) { pthread_mutex_lock( &mutex ); // look for free Thread slot for(int i=0;i<HTTPD_MAX_CONNECTIONS;i++) if(Connection_Thread_List[i] == (pthread_t)NULL) { index = i; break; } if(index == -1) { dperror("Maximum Connection-Threads reached\n"); pthread_mutex_unlock( &mutex ); return false; } newConn->thread_number = index; //remember Index of Thread slot (for clean up) // Create an orphan Thread. It is not joinable anymore pthread_mutex_unlock( &mutex ); // start connection Thread if(pthread_create(&Connection_Thread_List[index], &attr, WebThread, (void *)newConn) != 0) dperror("Could not create Connection-Thread\n"); } else // non threaded #endif WebThread((void *) newConn); return ((index != -1) || !is_threading); }