aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-12 09:17:03 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-12 09:17:03 +0100
commitc2101c8449488946f66f0b272e3506dcb5571e1c (patch)
tree48fab0c1d4c4c66849a0dbcae36bc3d85e0776e6 /src
parentf8fe3b1e2ed54ef05b718875da8d5dc1a76e9d1e (diff)
downloadrspamd-c2101c8449488946f66f0b272e3506dcb5571e1c.tar.gz
rspamd-c2101c8449488946f66f0b272e3506dcb5571e1c.zip
Implement reply writing for control socket.
Diffstat (limited to 'src')
-rw-r--r--src/libserver/rspamd_control.c52
-rw-r--r--src/libserver/rspamd_control.h5
2 files changed, 54 insertions, 3 deletions
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;
@@ -141,6 +145,50 @@ rspamd_control_connection_close (struct rspamd_control_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)
{
struct rspamd_control_reply_elt *elt = 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;