summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2012-05-18 11:45:07 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2012-05-18 11:45:07 +0200
commitc5effddd6d8edac976b40133f0f3b3d589bfe9b2 (patch)
treefe51c0ae67c979eb804d24ac0447e9557ea6ec3d
parent89ccf8e281aacb6dac7f6c530d4673144b9bbed9 (diff)
Always answer the client who sent the command. If no messages are needed (no observe) a ';' is sent.
-rw-r--r--src/munia_proto.cc8
1 files changed, 7 insertions, 1 deletions
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<message_t> msgqueue_t;
static std::map<struct libwebsocket *, msgqueue_t > 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);