diff src/anvil/connect-limit.c @ 10145:1110edddec36 HEAD

anvil: Added CONNECT-DUMP command to dump connect-limit state.
author Timo Sirainen <tss@iki.fi>
date Thu, 22 Oct 2009 20:28:46 -0400
parents 2e2b957f1cca
children 615eef3139c2
line wrap: on
line diff
--- a/src/anvil/connect-limit.c	Thu Oct 22 20:08:11 2009 -0400
+++ b/src/anvil/connect-limit.c	Thu Oct 22 20:28:46 2009 -0400
@@ -2,6 +2,9 @@
 
 #include "common.h"
 #include "hash.h"
+#include "str.h"
+#include "strescape.h"
+#include "ostream.h"
 #include "connect-limit.h"
 
 struct ident_pid {
@@ -164,3 +167,23 @@
 	}
 	hash_table_iterate_deinit(&iter);
 }
+
+void connect_limit_dump(struct connect_limit *limit, struct ostream *output)
+{
+	struct hash_iterate_context *iter;
+	void *key, *value;
+	string_t *str = t_str_new(256);
+
+	iter = hash_table_iterate_init(limit->ident_pid_hash);
+	while (hash_table_iterate(iter, &key, &value)) {
+		struct ident_pid *i = key;
+
+		str_truncate(str, 0);
+		str_tabescape_write(str, i->ident);
+		str_printfa(str, "\t%ld\t%u\n", (long)i->pid, i->refcount);
+		if (o_stream_send(output, str_data(str), str_len(str)) < 0)
+			break;
+	}
+	hash_table_iterate_deinit(&iter);
+	(void)o_stream_send(output, "\n", 1);
+}