vine-tool: timefd() bug fix 67/260167/3
authorSeonah Moon <seonah1.moon@samsung.com>
Mon, 21 Jun 2021 11:39:10 +0000 (20:39 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Tue, 22 Jun 2021 03:36:00 +0000 (12:36 +0900)
Change-Id: If1b7e6974c377b9401ff7bf21369fb655a8a6d17

packaging/capi-network-vine.spec
plugins/libwebsockets/libwebsockets-plugin.cpp
tool/tool_run.cpp

index bedbdf8..af6c230 100755 (executable)
@@ -3,7 +3,7 @@
 %bcond_without use_glib_event_loop
 Name:    capi-network-vine
 Summary: An service discovery framework
-Version: 1.0.8
+Version: 1.0.9
 Release: 0
 Group:   Network & Connectivity/API
 License: Apache-2.0
index 7669155..c901e51 100755 (executable)
@@ -563,9 +563,9 @@ static int _websocket_protocol_cb(struct lws *wsi,
                                vhd->vh, wsi, ws);
                if (ws && ws->wsi) {
                        ws->close_requested = true;
-                       lws_callback_on_writable(ws->wsi);
+                       return -1;
                }
-               return -1;
+               break;
 
        /* --- client callbacks --- */
        case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
index 82fa950..b9e600d 100644 (file)
@@ -63,6 +63,7 @@ static struct {
 static std::map<vine_dp_h, int> timerfds;
 static int send_message(vine_dp_h dp);
 static void _stop_message_timer(vine_dp_h dp);
+static int joined_peer = 0;
 
 static vine_dp_type_e _convert_dp_type(dp_type_t type)
 {
@@ -192,12 +193,19 @@ static void __accepted_cb(vine_dp_h dp, vine_dp_h accepted_dp, void *user_data)
 static void __peer_joined_cb(vine_dp_h dp, const char *peer_id, void *user_data)
 {
        printf("pubsub peer(%s) is joined.\n", peer_id);
-       send_message(dp);
+       ++joined_peer;
+       // if joined_peer is larger than 1,
+       // this means message timer has already runned.
+       if (joined_peer == 1)
+               send_message(dp);
 }
 
 static void __peer_left_cb(vine_dp_h dp, const char *peer_id, void *user_data)
 {
        printf("pubsub peer(%s) is left.\n", peer_id);
+       --joined_peer;
+       if (joined_peer == 0)
+               _stop_message_timer(dp);
 }
 
 static void __registered_cb(vine_session_h session,
@@ -263,7 +271,7 @@ static void _start_message_timer(vine_dp_h dp, int sec)
                return;
 
        struct itimerspec value;
-       value.it_interval.tv_sec = 0;
+       value.it_interval.tv_sec = sec;
        value.it_interval.tv_nsec = 0;
        value.it_value.tv_sec = sec;
        value.it_value.tv_nsec = 0;
@@ -291,6 +299,11 @@ static void _stop_message_timer(vine_dp_h dp)
                return;
        }
 
+       uint64_t buf;
+       int expired = read(timerfd, &buf, sizeof(uint64_t));
+       if (expired != sizeof(uint64_t))
+               printf("expired[%d]. operation failed.\n", expired);
+
        epoll_ctl(epollfd, EPOLL_CTL_DEL, timerfd, NULL);
        close(timerfd);
        timerfds.erase(it);