Browse Source

added event_handler setup; added srv->loop_flags; moved loop initialization to server_loop_init(); added ev_backend_string() to utils.c

personal/stbuehler/wip
Thomas Porzelt 14 years ago
parent
commit
c5fb96870c
  1. 1
      src/lighttpd.c
  2. 53
      src/plugin_core.c
  3. 23
      src/server.c
  4. 2
      src/server.h
  5. 14
      src/utils.c
  6. 2
      src/utils.h

1
src/lighttpd.c

@ -113,6 +113,7 @@ int main(int argc, char *argv[]) {
log_warning(srv, NULL, "test %s", "foo2");
log_debug(srv, NULL, "test %s", "message");
server_loop_init(srv);
server_start(srv);
server_free(srv);

53
src/plugin_core.c

@ -178,6 +178,7 @@ static action_result core_handle_test(server *srv, connection *con, gpointer par
gpointer k, v;
GList *hv;
GString *str;
gchar *backend;
guint64 uptime;
guint64 avg1, avg2, avg3;
gchar suffix1[2] = {0,0}, suffix2[2] = {0,0}, suffix3[2] = {0,0};
@ -218,6 +219,10 @@ static action_result core_handle_test(server *srv, connection *con, gpointer par
g_string_printf(str, "%"G_GUINT64_FORMAT"%s (%"G_GUINT64_FORMAT"%s/s)", avg1, suffix1, avg2, suffix2);
chunkqueue_append_string(con->out, str);
backend = ev_backend_string(ev_backend(srv->loop));
chunkqueue_append_mem(con->out, CONST_STR_LEN("\r\nevent handler: "));
chunkqueue_append_mem(con->out, backend, strlen(backend));
chunkqueue_append_mem(con->out, CONST_STR_LEN("\r\n\r\n--- headers ---\r\n"));
g_hash_table_iter_init(&iter, con->request.headers->table);
while (g_hash_table_iter_next(&iter, &k, &v)) {
@ -307,6 +312,53 @@ static gboolean core_listen(server *srv, plugin* p, option *opt) {
}
static gboolean core_event_handler(server *srv, plugin* p, option *opt) {
guint backend;
gchar *str;
UNUSED(p);
if (opt->type != OPTION_STRING) {
ERROR(srv, "%s", "event_handler expects a string as parameter");
return FALSE;
}
str = opt->value.opt_string->str;
backend = 0; /* libev will chose the right one by default */
if (g_str_equal(str, "select"))
backend = EVBACKEND_SELECT;
else if (g_str_equal(str, "poll"))
backend = EVBACKEND_POLL;
else if (g_str_equal(str, "epoll"))
backend = EVBACKEND_EPOLL;
else if (g_str_equal(str, "kqueue"))
backend = EVBACKEND_KQUEUE;
else if (g_str_equal(str, "devpoll"))
backend = EVBACKEND_DEVPOLL;
else if (g_str_equal(str, "port"))
backend = EVBACKEND_PORT;
else {
ERROR(srv, "unkown event handler: '%s'", str);
return FALSE;
}
if (backend) {
if (!(ev_supported_backends() & backend)) {
ERROR(srv, "unsupported event handler: '%s'", str);
return FALSE;
}
if (!(ev_recommended_backends() & backend)) {
TRACE(srv, "warning: event handler '%s' not recommended for this platform!", str);
}
}
srv->loop_flags |= backend;
return TRUE;
}
gboolean core_option_log_target_parse(server *srv, plugin *p, size_t ndx, option *opt, gpointer *value) {
log_t *log;
log_type_t log_type;
@ -380,6 +432,7 @@ static const plugin_action actions[] = {
static const plugin_setup setups[] = {
{ "listen", core_listen },
{ "event_handler", core_event_handler },
{ NULL, NULL }
};

23
src/server.c

@ -91,14 +91,6 @@ server* server_new() {
srv->magic = LIGHTTPD_SERVER_MAGIC;
srv->state = SERVER_STARTING;
srv->loop = ev_default_loop (0);
if (!srv->loop) {
fatal ("could not initialise libev, bad $LIBEV_FLAGS in environment?");
}
CATCH_SIGNAL(srv->loop, sigint_cb, INT);
CATCH_SIGNAL(srv->loop, sigint_cb, TERM);
CATCH_SIGNAL(srv->loop, sigpipe_cb, PIPE);
srv->connections_active = 0;
srv->connections = g_array_new(FALSE, TRUE, sizeof(connection*));
@ -194,6 +186,21 @@ void server_free(server* srv) {
g_slice_free(server, srv);
}
gboolean server_loop_init(server *srv) {
srv->loop = ev_default_loop(srv->loop_flags);
if (!srv->loop) {
fatal ("could not initialise libev, bad $LIBEV_FLAGS in environment?");
return FALSE;
}
CATCH_SIGNAL(srv->loop, sigint_cb, INT);
CATCH_SIGNAL(srv->loop, sigint_cb, TERM);
CATCH_SIGNAL(srv->loop, sigpipe_cb, PIPE);
return TRUE;
}
static connection* con_get(server *srv) {
connection *con;
if (srv->connections_active >= srv->connections->len) {

2
src/server.h

@ -37,6 +37,7 @@ struct server {
guint32 magic; /** server magic version, check against LIGHTTPD_SERVER_MAGIC in plugins */
server_state state;
guint loop_flags;
struct ev_loop *loop;
guint connections_active; /** 0..con_act-1: active connections, con_act..used-1: free connections */
@ -80,6 +81,7 @@ struct server {
LI_API server* server_new();
LI_API void server_free(server* srv);
LI_API gboolean server_loop_init(server *srv);
LI_API void server_listen(server *srv, int fd);

14
src/utils.c

@ -255,3 +255,17 @@ gchar counter_format(guint64 *count, guint factor) {
return suffix;
}
gchar *ev_backend_string(guint backend) {
switch (backend) {
case EVBACKEND_SELECT: return "select";
case EVBACKEND_POLL: return "poll";
case EVBACKEND_EPOLL: return "epoll";
case EVBACKEND_KQUEUE: return "kqueue";
case EVBACKEND_DEVPOLL: return "devpoll";
case EVBACKEND_PORT: return "port";
default: return "unknown";
}
}

2
src/utils.h

@ -22,4 +22,6 @@ LI_API gchar *http_status_string(guint status_code);
/* */
LI_API gchar counter_format(guint64 *count, guint factor);
LI_API gchar *ev_backend_string(guint backend);
#endif

Loading…
Cancel
Save