You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.2 KiB
C
81 lines
2.2 KiB
C
15 years ago
|
|
||
|
#include <lighttpd/base.h>
|
||
|
#include <lighttpd/angel.h>
|
||
|
|
||
14 years ago
|
static void angel_call_cb(liAngelConnection *acon,
|
||
14 years ago
|
const gchar *mod, gsize mod_len, const gchar *action, gsize action_len,
|
||
|
gint32 id, GString *data) {
|
||
14 years ago
|
liServer *srv = acon->data;
|
||
14 years ago
|
ERROR(srv, "received message for %s:%s, not implemented yet", mod, action);
|
||
14 years ago
|
if (-1 != id) li_angel_send_result(acon, id, g_string_new_len(CONST_STR_LEN("not implemented yet")), NULL, NULL, NULL);
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
static void angel_close_cb(liAngelConnection *acon, GError *err) {
|
||
|
liServer *srv = acon->data;
|
||
14 years ago
|
ERROR(srv, "li_fatal: angel connection close: %s", err ? err->message : g_strerror(errno));
|
||
14 years ago
|
if (err) g_error_free(err);
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
14 years ago
|
void li_angel_setup(liServer *srv) {
|
||
|
srv->acon = li_angel_connection_new(srv->loop, 0, srv, angel_call_cb, angel_close_cb);
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
static void li_angel_listen_cb(liAngelCall *acall, gpointer ctx, gboolean timeout, GString *error, GString *data, GArray *fds) {
|
||
14 years ago
|
liServer *srv = ctx;
|
||
14 years ago
|
guint i;
|
||
|
UNUSED(data);
|
||
|
|
||
14 years ago
|
li_angel_call_free(acall);
|
||
14 years ago
|
|
||
|
ERROR(srv, "%s", "listen_cb");
|
||
|
|
||
|
if (timeout) {
|
||
|
ERROR(srv, "listen failed: %s", "time out");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (error->len > 0) {
|
||
|
ERROR(srv, "listen failed: %s", error->str);
|
||
|
/* TODO: exit? */
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (fds && fds->len > 0) {
|
||
|
for (i = 0; i < fds->len; i++) {
|
||
|
INFO(srv, "listening on fd %i", g_array_index(fds, int, i));
|
||
14 years ago
|
li_server_listen(srv, g_array_index(fds, int, i));
|
||
14 years ago
|
}
|
||
|
g_array_set_size(fds, 0);
|
||
|
} else {
|
||
|
ERROR(srv, "listen failed: %s", "received no filedescriptors");
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
/* listen to a socket */
|
||
14 years ago
|
void li_angel_listen(liServer *srv, GString *str) {
|
||
14 years ago
|
if (srv->acon) {
|
||
14 years ago
|
liAngelCall *acall = li_angel_call_new(li_angel_listen_cb, 3.0);
|
||
14 years ago
|
GError *err = NULL;
|
||
|
|
||
|
acall->context = srv;
|
||
14 years ago
|
if (!li_angel_send_call(srv->acon, CONST_STR_LEN("core"), CONST_STR_LEN("listen"), acall, g_string_new_len(GSTR_LEN(str)), &err)) {
|
||
14 years ago
|
ERROR(srv, "couldn't send call: %s", err->message);
|
||
|
g_error_free(err);
|
||
|
}
|
||
|
} else {
|
||
|
int fd = angel_fake_listen(srv, str);
|
||
|
if (-1 == fd) {
|
||
|
ERROR(srv, "listen('%s') failed", str->str);
|
||
|
/* TODO: exit? */
|
||
|
} else {
|
||
14 years ago
|
li_server_listen(srv, fd);
|
||
14 years ago
|
}
|
||
|
}
|
||
15 years ago
|
}
|
||
|
|
||
|
/* send log messages while startup to angel */
|
||
14 years ago
|
void li_angel_log(liServer *srv, GString *str) {
|
||
14 years ago
|
angel_fake_log(srv, str);
|
||
15 years ago
|
}
|