Allow only a single write operation per one writable callback 80/143080/2
authorJi-hoon Lee <dalton.lee@samsung.com>
Tue, 8 Aug 2017 10:05:07 +0000 (19:05 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Thu, 10 Aug 2017 00:31:17 +0000 (00:31 +0000)
Change-Id: I87b2bca02eb6832f84c1cc3a213d16c7f42c92eb

src/legacy_support/websocket.cpp

index aa82219..507f3b8 100644 (file)
@@ -127,7 +127,7 @@ static int callback_keyboard(struct lws *wsi,
             if (pss->valid) {
                 pthread_mutex_lock(&g_ws_server_mutex);
                 std::queue<ISE_MESSAGE>& messages = agent->get_send_message_queue();
-                while (messages.size() > 0) {
+                if (messages.size() > 0) {
                     ISE_MESSAGE &message = messages.front();
                     std::string str = CISEMessageSerializer::serialize(message);
                     LOGD("SEND_WEBSOCKET_MESSAGE : %s", str.c_str());
@@ -139,9 +139,13 @@ static int callback_keyboard(struct lws *wsi,
                 pthread_mutex_unlock(&g_ws_server_mutex);
 
                 if (n < 0) {
-                    lwsl_err("ERROR %d writing to di socket\n", n);
+                    LOGE("ERROR %d writing to di socket\n", n);
                     return -1;
                 }
+
+                if (messages.size() > 0) {
+                    lws_callback_on_writable_all_protocol(g_ws_server_context, &protocols[PROTOCOL_KEYBOARD]);
+                }
             } else {
                 LOGD("Rejecting data transmission since client is not valid");
             }