void do_petition_set_threaded(float wait_s, float wait_c, int nrequests, char close, int nthreads){ ONION_DEBUG("Using %d threads, %d petitions per thread",nthreads,nrequests); processed=0; params_t params; params.wait_s=wait_s; params.wait_t=wait_c; params.n_requests=nrequests; params.close_at_n=close; pthread_t *thread=malloc(sizeof(pthread_t*)*nthreads); pthread_t listen_thread; int i; pthread_create(&listen_thread, NULL, (void*)do_listen, NULL); for (i=0;i<nthreads;i++){ pthread_create(&thread[i], NULL, (void*)do_requests, ¶ms); } for (i=0;i<nthreads;i++){ pthread_join(thread[i], NULL); } free(thread); if (close==2){ usleep(wait_s*1000000); onion_listen_stop(o); } pthread_join(listen_thread, NULL); FAIL_IF_NOT_EQUAL_INT(params.n_requests * nthreads, processed); }
int OnionServer::stop_server() { onion_listen_stop(m_ponion);//stop loop int i = pthread_join( m_pthread, NULL);//wait till loop ends onion_free(m_ponion); return i; }
/** * @short Removes the allocated data * @memberof onion_t */ void onion_free(onion *onion){ ONION_DEBUG("Onion free"); onion_listen_stop(onion); if (onion->poller) onion_poller_free(onion->poller); if (onion->username) free(onion->username); if (onion->listen_points){ onion_listen_point **p=onion->listen_points; while(*p!=NULL){ ONION_DEBUG("Free %p listen_point", *p); onion_listen_point_free(*p++); } free(onion->listen_points); } if (onion->root_handler) onion_handler_free(onion->root_handler); if (onion->internal_error_handler) onion_handler_free(onion->internal_error_handler); onion_mime_set(NULL); if (onion->sessions) onion_sessions_free(onion->sessions); #ifdef HAVE_PTHREADS if (onion->threads) free(onion->threads); #endif free(onion); }
void t01_listen_port_error_handler(onion_log_level level, const char *filename, int lineno, const char *fmt, ...) { if (level == O_ERROR && (errno == EBADF || errno == EDOTDOT)){ if (!t01_failed) { t01_failed = true; onion_listen_stop(t01_server); } } }
/** * @short Removes the allocated data * @memberof onion_t */ void onion_free(onion *onion){ ONION_DEBUG("Onion free"); if (onion->flags&O_LISTENING) onion_listen_stop(onion); if (onion->poller) onion_poller_free(onion->poller); if (onion->username) onion_low_free(onion->username); if (onion->listen_points){ onion_listen_point **p=onion->listen_points; while(*p!=NULL){ ONION_DEBUG("Free %p listen_point", *p); onion_listen_point_free(*p++); } onion_low_free(onion->listen_points); } if (onion->root_handler) onion_handler_free(onion->root_handler); if (onion->internal_error_handler) onion_handler_free(onion->internal_error_handler); onion_mime_set(NULL); if (onion->sessions) onion_sessions_free(onion->sessions); { #ifdef HAVE_PTHREADS pthread_mutex_lock (&onion->mutex); #endif void* data = onion->client_data; onion->client_data = NULL; if (data && onion->client_data_free) onion->client_data_free (data); onion->client_data_free = NULL; #ifdef HAVE_PTHREADS pthread_mutex_unlock (&onion->mutex); pthread_mutex_destroy (&onion->mutex); #endif }; #ifdef HAVE_PTHREADS if (onion->threads) onion_low_free(onion->threads); #endif if (!(onion->flags&O_NO_SIGTERM)){ signal(SIGINT,SIG_DFL); signal(SIGTERM,SIG_DFL); } last_onion=NULL; onion_low_free(onion); }
static void shutdown_server(int _){ static bool first_call=true; if (first_call){ if (last_onion){ onion_listen_stop(last_onion); ONION_INFO("Exiting onion listening (SIG%s)", _==SIGTERM ? "TERM" : "INT"); } } else{ ONION_ERROR("Aborting as onion does not stop listening."); abort(); } first_call=false; }
void *do_requests(params_t *t){ const char *url="http://localhost:8080/"; CURL *curl=prepare_curl(url); ONION_DEBUG("Do %d petitions",t->n_requests); int i; usleep(t->wait_s*1000000); for(i=0;i<t->n_requests;i++){ curl_get(curl, url); usleep(t->wait_t*1000000); } if (t->close_at_n==1){ usleep(t->wait_s*1000000); onion_listen_stop(o); } curl_easy_cleanup(curl); return NULL; }
static void shutdown_server(int _){ if (o) onion_listen_stop(o); }
/** * @short Stops the listening for connections. */ void listenStop() { onion_listen_stop(ptr); }
void onexit(int sig){ ONION_INFO("Exit"); kill(child, sig); if (o) onion_listen_stop(o); }