From: Vsevolod Stakhov Date: Mon, 12 Oct 2015 08:17:03 +0000 (+0100) Subject: Implement reply writing for control socket. X-Git-Tag: 1.0.5~36 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c2101c8449488946f66f0b272e3506dcb5571e1c;p=rspamd.git Implement reply writing for control socket. --- diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c index 8d9067053..24d527025 100644 --- a/src/libserver/rspamd_control.c +++ b/src/libserver/rspamd_control.c @@ -33,6 +33,10 @@ static struct timeval io_timeout = { .tv_sec = 30, .tv_usec = 0 }; +static struct timeval worker_io_timeout = { + .tv_sec = 0, + .tv_usec = 500000 +}; struct rspamd_control_session; @@ -140,6 +144,50 @@ rspamd_control_connection_close (struct rspamd_control_session *session) g_slice_free1 (sizeof (*session), session); } +static void +rspamd_control_write_reply (struct rspamd_control_session *session) +{ + ucl_object_t *rep, *cur; + struct rspamd_control_reply_elt *elt; + gchar tmpbuf[64]; + + rep = ucl_object_typed_new (UCL_OBJECT); + + DL_FOREACH (session->replies, elt) { + rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "%p", elt->wrk->pid); + cur = ucl_object_typed_new (UCL_OBJECT); + + ucl_object_insert_key (cur, ucl_object_fromstring (g_quark_to_string ( + elt->wrk->type)), "type", 0, false); + + switch (elt->session->cmd.type) { + case RSPAMD_CONTROL_STAT: + ucl_object_insert_key (cur, ucl_object_fromint ( + elt->reply.reply.stat.conns), "conns", 0, false); + ucl_object_insert_key (cur, ucl_object_fromdouble ( + elt->reply.reply.stat.utime), "utime", 0, false); + ucl_object_insert_key (cur, ucl_object_fromdouble ( + elt->reply.reply.stat.systime), "systime", 0, false); + ucl_object_insert_key (cur, ucl_object_fromdouble ( + elt->reply.reply.stat.uptime), "uptime", 0, false); + ucl_object_insert_key (cur, ucl_object_fromint ( + elt->reply.reply.stat.maxrss), "maxrss", 0, false); + break; + case RSPAMD_CONTROL_RELOAD: + ucl_object_insert_key (cur, ucl_object_fromint ( + elt->reply.reply.reload.status), "status", 0, false); + break; + default: + break; + } + + ucl_object_insert_key (rep, cur, tmpbuf, 0, true); + } + + rspamd_control_send_ucl (session, rep); + ucl_object_unref (rep); +} + static void rspamd_control_wrk_io (gint fd, short what, gpointer ud) { @@ -155,7 +203,7 @@ rspamd_control_wrk_io (gint fd, short what, gpointer ud) event_del (&elt->io_ev); if (elt->session->replies_remain == 0) { - /* TODO: add reply logic */ + rspamd_control_write_reply (elt->session); rspamd_control_connection_close (elt->session); } } @@ -229,7 +277,7 @@ rspamd_control_finish_hadler (struct rspamd_http_connection *conn, rep_elt); event_base_set (session->rspamd_main->ev_base, &rep_elt->io_ev); - event_add (&rep_elt->io_ev, &io_timeout); + event_add (&rep_elt->io_ev, &worker_io_timeout); DL_APPEND (session->replies, rep_elt); session->replies_remain ++; diff --git a/src/libserver/rspamd_control.h b/src/libserver/rspamd_control.h index 2863f2988..09143c6f8 100644 --- a/src/libserver/rspamd_control.h +++ b/src/libserver/rspamd_control.h @@ -53,7 +53,10 @@ struct rspamd_control_reply { union { struct { guint conns; - guint64 uptime; + gdouble uptime; + gdouble utime; + gdouble systime; + gulong maxrss; } stat; struct { guint status;