Index: src_plugins/hid_srv_ws/server.c =================================================================== --- src_plugins/hid_srv_ws/server.c (revision 10622) +++ src_plugins/hid_srv_ws/server.c (revision 10623) @@ -30,6 +30,7 @@ #include #include #include +#include #include "plugins.h" #include "error.h" @@ -47,6 +48,7 @@ static hid_srv_ws_t hid_srv_ws_ctx; + static int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { int n; @@ -211,6 +213,8 @@ } else { /* parent */ + hid_srv_ws_client_t *cl = calloc(sizeof(hid_srv_ws_client_t), 1); + htip_set(&ctx->clients, p, cl); if (ctx->pollfds[n].fd > 0) ctx->pollfds[n].fd = -ctx->pollfds[n].fd; /* disable listen until the client finished accepting */ pcb_message(PCB_MSG_INFO, "websocket [%d]: new client conn forked\n", ctx->pid); @@ -240,8 +244,17 @@ } else { /* no revents, but before polling again, make lws check for any timeouts */ if (ms - ms_1sec > 1000) { + static int ctr = 0; lws_service_fd(ctx->context, NULL); ms_1sec = ms; + + if ((ctx->pollfds[0].fd > 0) && ((ctr++ % 5) == 0)) { /* server: print client stats */ + htip_entry_t *e; + pcb_message(PCB_MSG_INFO, "Client stats:\n"); + for (e = htip_first(&ctx->clients); e; e = htip_next(&ctx->clients, e)) { + pcb_message(PCB_MSG_INFO, "[%d]\n", e->key); + } + } } } } @@ -278,7 +291,9 @@ ctx->listen_fd = -1; ctx->pid = getpid(); + htip_init(&ctx->clients, longhash, longkeyeq); + /* create lws context representing this server */ ctx->context = lws_create_context(&context_info); if (ctx->context == NULL) { Index: src_plugins/hid_srv_ws/server.h =================================================================== --- src_plugins/hid_srv_ws/server.h (revision 10622) +++ src_plugins/hid_srv_ws/server.h (revision 10623) @@ -25,6 +25,7 @@ #include #include +#include /* Number of sockets to handle - need one listening socket and one accepted because each client is forked; leave some room for retries and whatnot */ @@ -40,6 +41,12 @@ int num_clients; int c2s[2]; /* Client to server communication; 0 is read by the server, 1 is written by clients */ + + htip_t clients; } hid_srv_ws_t; +typedef struct { + char *user; +} hid_srv_ws_client_t; + #endif