From c5effddd6d8edac976b40133f0f3b3d589bfe9b2 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 18 May 2012 11:45:07 +0200 Subject: Always answer the client who sent the command. If no messages are needed (no observe) a ';' is sent. --- src/munia_proto.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/munia_proto.cc b/src/munia_proto.cc index 480ba39..6f42c28 100644 --- a/src/munia_proto.cc +++ b/src/munia_proto.cc @@ -83,6 +83,7 @@ static void dump_handshake_info(struct lws_tokens *lwst) typedef std::list msgqueue_t; static std::map msgqueue; +struct libwebsocket *current_client = NULL; int callback_lws_task(struct libwebsocket_context * context, struct libwebsocket *wsi, @@ -141,6 +142,8 @@ int callback_lws_task(struct libwebsocket_context * context, std::string msgstr; msgstr.append((size_t)LWS_SEND_BUFFER_PRE_PADDING, ' '); + if(msgqueue[wsi].size() == 0 && wsi == current_client) msgstr += ";"; + while(msgqueue[wsi].size() > 0) { message_t msg = msgqueue[wsi].front(); msgqueue[wsi].pop_front(); @@ -149,7 +152,8 @@ int callback_lws_task(struct libwebsocket_context * context, if(msgstr.size() > LWS_SEND_BUFFER_PRE_PADDING) msgstr += " "; msgstr += std::string(buf) + " " + msg_tostring(msg); } - + + msgstr.append((size_t)LWS_SEND_BUFFER_POST_PADDING, ' '); int n = libwebsocket_write(wsi, (unsigned char *) @@ -179,6 +183,8 @@ int callback_lws_task(struct libwebsocket_context * context, { printf("LWS_CALLBACK_RECEIVE\n"); + current_client = wsi; + printf("%s\n", (char*)in); std::string data; data.append((char*)in, len); -- cgit v1.2.3