Browse code

modules/websocket: More tidying up

Peter Dunkley authored on 21/06/2012 16:37:08
Showing 2 changed files
... ...
@@ -31,10 +31,10 @@ gen_lock_t *wsconn_lock = NULL;
31 31
 
32 32
 char *wsconn_state_str[] =
33 33
 {
34
-	"CONNECTING",
35
-	"OPEN",
36
-	"CLOSING",
37
-	"CLOSED"
34
+	"CONNECTING",	/* WS_S_CONNECTING */
35
+	"OPEN",		/* WS_S_OPEN */
36
+	"CLOSING",	/* WS_S_CLOSING */
37
+	"CLOSED"	/* WS_S_CLOSED */
38 38
 };
39 39
 
40 40
 static inline void _wsconn_rm(ws_connection_t *wsc);
... ...
@@ -39,6 +39,9 @@
39 39
 
40 40
 MODULE_VERSION
41 41
 
42
+/* Maximum number of connections to display when using the ws.dump MI command */
43
+#define MAX_WS_CONNS_DUMP	50
44
+
42 45
 extern gen_lock_t *tcpconn_lock;
43 46
 extern struct tcp_connection **tcpconn_id_hash;
44 47
 
... ...
@@ -197,7 +200,7 @@ static void destroy(void)
197 200
 
198 201
 static struct mi_root *mi_dump(struct mi_root *cmd, void *param)
199 202
 {
200
-	int h, connections = 0, interval;
203
+	int h, connections = 0, truncated = 0, interval;
201 204
 	char *src_proto, *dst_proto;
202 205
 	char src_ip[IP6_MAX_STR_SIZE + 1], dst_ip[IP6_MAX_STR_SIZE + 1];
203 206
 	ws_connection_t *wsc;
... ...
@@ -243,7 +246,11 @@ static struct mi_root *mi_dump(struct mi_root *cmd, void *param)
243 246
 						interval) == 0)
244 247
 					return 0;
245 248
 
246
-				connections++;
249
+				if (++connections == MAX_WS_CONNS_DUMP)
250
+				{
251
+					truncated = 1;
252
+					break;
253
+				}
247 254
 			}
248 255
 
249 256
 			wsc = wsc->next;
... ...
@@ -252,8 +259,9 @@ static struct mi_root *mi_dump(struct mi_root *cmd, void *param)
252 259
 	WSCONN_UNLOCK;
253 260
 
254 261
 	if (addf_mi_node_child(&rpl_tree->node, 0, 0, 0,
255
-				"%d WebSocket connection%s found",
256
-				connections, connections == 1 ? "" : "s") == 0)
262
+				"%d WebSocket connection%s found%s",
263
+				connections, connections == 1 ? "" : "s",
264
+				truncated == 1 ? "(truncated)" : "") == 0)
257 265
 		return 0;
258 266
 
259 267
 	return rpl_tree;