Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Libevent2 #35

Open
wants to merge 2 commits into from

1 participant

@jehiah
Owner

Work in progress, but this is to cover some exploratory changes to switch to libevent2. The end of this may or may not result in immediate merging of this, but it will help define the scope of changes necessary to link against libevent2.

@jehiah
Owner

short summary is this: libevent2 transition is pretty straight forward.

A few methods are depreciated, and we could continue using them, but we should switch to new methods that take an explicit event_base (exposed now as simplehttp_event_base). Other stuff that are old structures which aren't ideal to use have *_compat.h includes or *_struct.h includes that just need to be added; using those makes things brittle as it introduces binary incompatibility, but there isn't any other downside to using them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  simplehttp/async_simplehttp.c
@@ -4,6 +4,7 @@
#include <inttypes.h>
#include <time.h>
#include "async_simplehttp.h"
+#include <event2/http_struct.h>
// 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);
View
2  simplehttp/log.c
@@ -4,6 +4,8 @@
#include <string.h>
#include <inttypes.h>
#include "simplehttp.h"
+#include <event2/http_struct.h>
+#include <event2/buffer_compat.h>
const char *simplehttp_method(struct evhttp_request *req)
{
View
34 simplehttp/simplehttp.c
@@ -12,11 +12,15 @@
#include <string.h>
#include <stdio.h>
#include <fnmatch.h>
+
#include "queue.h"
#include "simplehttp.h"
#include "stat.h"
#include "request.h"
#include "options.h"
+#include <event2/http_struct.h>
+#include <event2/http_compat.h>
+#include <event2/event_struct.h>
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()
View
8 simplehttp/simplehttp.h
@@ -2,9 +2,10 @@
#define _SIMPLEHTTP_H
#include "queue.h"
+#include <event2/event.h>
+#include <event2/buffer.h>
+#include <event2/http.h>
#include "options.h"
-#include <event.h>
-#include <evhttp.h>
#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);
Something went wrong with that request. Please try again.