]> source.dussan.org Git - rspamd.git/commitdiff
Implement reply writing for control socket.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 12 Oct 2015 08:17:03 +0000 (09:17 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 12 Oct 2015 08:17:03 +0000 (09:17 +0100)
src/libserver/rspamd_control.c
src/libserver/rspamd_control.h

index 8d90670539fa4a9d88dc5d0a4f00320070baa0b3..24d527025c9666c7c0af6539105676a8d4b89392 100644 (file)
@@ -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 ++;
index 2863f2988ea64b73408727bb4a7d67d2fc575745..09143c6f8b547a3b7435fbe7c171b0bea66aae1d 100644 (file)
@@ -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;