static void shut_down(void) { int cnum; for (cnum = 0; cnum < AVAILABLE_FDS; ++cnum) { if (connects[cnum].conn_state != CNST_FREE) { httpd_close_conn(connects[cnum].hc); } if (connects[cnum].hc != NULL) { httpd_destroy_conn(connects[cnum].hc); httpd_free((void *)connects[cnum].hc); connects[cnum].hc = NULL; } } if (hs) { httpd_server *ths = hs; hs = NULL; if (ths->listen_fd != -1) { fdwatch_del_fd(fw, ths->listen_fd); } httpd_terminate(ths); } tmr_destroy(); httpd_free((void *)connects); }
static void shut_down( void ) { int cnum; struct timeval tv; (void) gettimeofday( &tv, (struct timezone*) 0 ); for ( cnum = 0; cnum < max_connects; ++cnum ) { if ( connects[cnum].conn_state != CNST_FREE ) httpd_close_conn( connects[cnum].hc, &tv ); if ( connects[cnum].hc != (httpd_conn*) 0 ) { httpd_destroy_conn( connects[cnum].hc ); free( (void*) connects[cnum].hc ); --httpd_conn_count; connects[cnum].hc = (httpd_conn*) 0; } } if ( hs != (httpd_server*) 0 ) { httpd_server* ths = hs; hs = (httpd_server*) 0; if ( ths->listen4_fd != -1 ) fdwatch_del_fd( ths->listen4_fd ); if ( ths->listen6_fd != -1 ) fdwatch_del_fd( ths->listen6_fd ); httpd_terminate( ths ); } tmr_destroy(); free( (void*) connects ); }
static void shut_down( void ) { int cnum; struct timeval tv; (void) gettimeofday( &tv, (struct timezone*) 0 ); logstats( &tv ); for ( cnum = 0; cnum < maxconnects; ++cnum ) { if ( connects[cnum].conn_state != CNST_FREE ) httpd_close_conn( connects[cnum].hc, &tv ); if ( connects[cnum].hc != (httpd_conn*) 0 ) { httpd_destroy_conn( connects[cnum].hc ); free( (void*) connects[cnum].hc ); --httpd_conn_count; connects[cnum].hc = (httpd_conn*) 0; } } if ( hs != (httpd_server*) 0 ) { httpd_server* ths = hs; hs = (httpd_server*) 0; httpd_terminate( ths ); } mmc_destroy(); tmr_destroy(); free( (void*) connects ); if ( throttles != (throttletab*) 0 ) free( (void*) throttles ); }
static void really_clear_connection( connecttab* c, struct timeval* tvP ) { stats_bytes += c->bytes_to_send; fdwatch_del_fd( c->hc->conn_fd ); httpd_close_conn( c->hc, tvP ); clear_throttles( c, tvP ); if ( c->linger_timer != (Timer*) 0 ) { tmr_cancel( c->linger_timer ); c->linger_timer = 0; } c->conn_state = CNST_FREE; --numconnects; }
static void really_clear_connection(struct connect_s *conn) { fdwatch_del_fd(fw, conn->hc->conn_fd); httpd_close_conn(conn->hc); if (conn->linger_timer != NULL) { tmr_cancel(conn->linger_timer); conn->linger_timer = 0; } /* Put the connection structure back on the free list */ conn->conn_state = CNST_FREE; conn->next = free_connections; free_connections = conn; }
static void really_clear_connection( connecttab* c, struct timeval* tvP ) { stats_bytes += c->hc->bytes_sent; if ( c->conn_state != CNST_PAUSING && c->conn_state != CNST_SLEEPING ) fdwatch_del_fd( c->hc->conn_fd ); httpd_close_conn( c->hc, tvP ); if ( c->linger_timer != (Timer*) 0 ) { tmr_cancel( c->linger_timer ); c->linger_timer = 0; } c->conn_state = CNST_FREE; c->next_free_connect = first_free_connect; first_free_connect = c - connects; /* division by sizeof is implied */ --num_connects; }
int32 PoorManServer::_Worker(void* data) { static const struct timeval kTimeVal = {60, 0}; PoorManServer* s = static_cast<PoorManServer*>(data); httpd_conn* hc; int retval; if (has_data(find_thread(NULL))) { thread_id sender; if (receive_data(&sender, &hc, sizeof(httpd_conn*)) != 512) goto cleanup; } else { // No need to go throught the whole cleanup, as we haven't open // nor allocated ht yet. atomic_add(&s->fCurConns, -1); return 0; } PRINT(("A worker thread starts to work.\n")); setsockopt(hc->conn_fd, SOL_SOCKET, SO_RCVTIMEO, &kTimeVal, sizeof(struct timeval)); retval = recv( hc->conn_fd, &(hc->read_buf[hc->read_idx]), hc->read_size - hc->read_idx, 0 ); if (retval < 0) goto cleanup; hc->read_idx += retval; switch(httpd_got_request(hc)) { case GR_GOT_REQUEST: break; case GR_BAD_REQUEST: httpd_send_err(hc, 400, httpd_err400title, (char *)"", httpd_err400form, (char *)""); httpd_write_response(hc);//fall through case GR_NO_REQUEST: //fall through default: //won't happen goto cleanup; break; } if (httpd_parse_request(hc) < 0) { httpd_write_response(hc); goto cleanup; } retval = httpd_start_request(hc, (struct timeval*)0); if (retval < 0) { httpd_write_response(hc); goto cleanup; } /*true means the connection is already handled *by the directory index generator in httpd_start_request(). */ if (hc->file_address == (char*) 0) { static_cast<PoorManApplication*>(be_app)->GetPoorManWindow()->SetHits( static_cast<PoorManApplication*>(be_app)->GetPoorManWindow()->GetHits() + 1 ); hc->conn_fd = -1; goto cleanup; } switch (hc->method) { case METHOD_GET: s->_HandleGet(hc); break; case METHOD_HEAD: s->_HandleHead(hc); break; case METHOD_POST: s->_HandlePost(hc); break; } cleanup: ; httpd_close_conn(hc, (struct timeval*)0); httpd_destroy_conn(hc); delete hc; atomic_add(&s->fCurConns, -1); return 0; }