diff --git a/simplehttp/async_simplehttp.c b/simplehttp/async_simplehttp.c index 8c0591d..0ba33b1 100644 --- a/simplehttp/async_simplehttp.c +++ b/simplehttp/async_simplehttp.c @@ -4,6 +4,7 @@ #include #include #include "async_simplehttp.h" +#include // this is set as a parameter to init_async_connection_pool() static int request_logging = 0; @@ -65,7 +66,7 @@ struct evhttp_connection *get_connection(char *address, int port, struct Connect conn->port = port; conn->next_evcon = 0; for (i = 0; i < ASYNC_PER_HOST_CONNECTION_LIMIT; i++) { - conn->evcon[i] = evhttp_connection_new(address, port); + conn->evcon[i] = evhttp_connection_base_new(simplehttp_event_base, NULL, address, port); evhttp_connection_set_retries(conn->evcon[i], 0); } TAILQ_INSERT_TAIL(&connection_pool, conn, next); diff --git a/simplehttp/log.c b/simplehttp/log.c index 063a30a..6c72f96 100644 --- a/simplehttp/log.c +++ b/simplehttp/log.c @@ -4,6 +4,8 @@ #include #include #include "simplehttp.h" +#include +#include const char *simplehttp_method(struct evhttp_request *req) { diff --git a/simplehttp/simplehttp.c b/simplehttp/simplehttp.c index 9000888..4398dcb 100644 --- a/simplehttp/simplehttp.c +++ b/simplehttp/simplehttp.c @@ -12,11 +12,15 @@ #include #include #include + #include "queue.h" #include "simplehttp.h" #include "stat.h" #include "request.h" #include "options.h" +#include +#include +#include typedef struct cb_entry { char *path; @@ -30,8 +34,8 @@ int simplehttp_logging = 0; int callback_count = 0; uint64_t request_count = 0; struct evhttp *httpd; -struct event pipe_ev; -extern struct event_base *current_base; +struct event *pipe_ev; +struct event_base *simplehttp_event_base = NULL; int help_cb(int *value); @@ -41,7 +45,7 @@ static void ignore_cb(int sig, short what, void *arg) void termination_handler(int signum) { - event_loopbreak(); + simplehttp_loopbreak(); } int get_uid(char *user) @@ -149,8 +153,8 @@ void generic_request_handler(struct evhttp_request *req, void *arg) void simplehttp_init() { - if (!current_base) { - event_init(); + if (!simplehttp_event_base) { + simplehttp_event_base = event_base_new(); } TAILQ_INIT(&callbacks); TAILQ_INIT(&simplehttp_reqs); @@ -165,7 +169,9 @@ void simplehttp_free() free(entry->path); free(entry); } + event_free(pipe_ev); evhttp_free(httpd); + event_base_free(simplehttp_event_base); simplehttp_stats_destruct(); } @@ -249,10 +255,10 @@ int simplehttp_listen() if (root != NULL) { if (chroot(root) != 0) { - err(1, strerror(errno)); + err(1, "%s", strerror(errno)); } if (chdir("/") != 0) { - err(1, strerror(errno)); + err(1, "%s", strerror(errno)); } } @@ -278,13 +284,13 @@ int simplehttp_listen() signal(SIGQUIT, termination_handler); signal(SIGTERM, termination_handler); - signal_set(&pipe_ev, SIGPIPE, ignore_cb, NULL); - signal_add(&pipe_ev, NULL); + pipe_ev = event_new(simplehttp_event_base, SIGPIPE, EV_SIGNAL|EV_PERSIST, ignore_cb, NULL); + event_add(pipe_ev, NULL); simplehttp_stats_init(); - httpd = evhttp_start(address, port); - if (!httpd) { + httpd = evhttp_new(simplehttp_event_base); + if (evhttp_bind_socket(httpd, address, port) == -1) { printf("could not bind to %s:%d\n", address, port); return 0; } @@ -295,9 +301,13 @@ int simplehttp_listen() return 1; } +void simplehttp_loopbreak() +{ + event_base_loopbreak(simplehttp_event_base); +} void simplehttp_run() { - event_dispatch(); + event_base_dispatch(simplehttp_event_base); } int simplehttp_main() diff --git a/simplehttp/simplehttp.h b/simplehttp/simplehttp.h index b706c48..607f829 100644 --- a/simplehttp/simplehttp.h +++ b/simplehttp/simplehttp.h @@ -2,9 +2,10 @@ #define _SIMPLEHTTP_H #include "queue.h" +#include +#include +#include #include "options.h" -#include -#include #define SIMPLEHTTP_VERSION "0.1.2" #ifndef DUPE_N_TERMINATE @@ -40,9 +41,12 @@ struct simplehttp_stats { int callback_count; }; +extern struct event_base *simplehttp_event_base; + void simplehttp_init(); int simplehttp_main(); int simplehttp_listen(); +void simplehttp_loopbreak(); void simplehttp_run(); void simplehttp_free(); void simplehttp_set_cb(char *path, void (*cb)(struct evhttp_request *, struct evbuffer *, void *), void *ctx);