Changed not to start pingpong for local channel 93/131293/1
authorkmook <kmook.choi@samsung.com>
Fri, 26 May 2017 07:17:46 +0000 (16:17 +0900)
committerkmook <kmook.choi@samsung.com>
Fri, 26 May 2017 07:17:46 +0000 (16:17 +0900)
Change-Id: I0f0656294ff2429ec3c5b7d2ee6161af44a2b3dd
Signed-off-by: kmook <kmook.choi@samsung.com>
msf_tizen_client/include/Channel.h
msf_tizen_client/src/Channel.cpp

index d3def87cc94d0dfa45487fab570157c833c6f89c..a6affbb4870c02a0f9611ffe15097151c884fb1b 100755 (executable)
@@ -320,6 +320,7 @@ private:
        bool IsSecureSupport = false;
        bool IsSecureMode = false;
        bool isCommunicated = false;
+       bool isLocalChannel = false;
 };
 
 #endif
index b0045fd1c121e6d57efae78d92395cb85186695c..3bbe60d9a3a01f736ee4be61adfe55a39391d90c 100755 (executable)
@@ -61,7 +61,7 @@ pthread_t Channel::connect_thread;
 JsonObject *Channel::root_json_object = NULL;
 
 ChannelConnectionHandler::ChannelConnectionHandler() {
-       pingTimeout = 5000000;
+       pingTimeout = 5000;
        lastPingReceived = 0;
        running = false;
        longestRT = 0;
@@ -442,6 +442,10 @@ void Channel::setConnectionTimeout(long timeout) {
        } else if (timeout == 0) {
                connectionHandler->stopPing();
        } else {
+               if (isLocalChannel) {
+                       MSF_DBG("local channel. startPing was skipped");
+                       return;
+               }
                connectionHandler->setPingTimeout(timeout);
                if (isWebSocketOpen()) {
                        connectionHandler->startPing(this);
@@ -777,6 +781,10 @@ void Channel::handleConnect(string UID) {
        if (onConnectListener) {
                onConnectListener->onConnect(clienttemp);
        }
+       if (isLocalChannel) {
+               MSF_DBG("local channel. startPing was skipped");
+               return;
+       }
        // To start channnel health check
        if (isWebSocketOpen()) {
                connectionHandler->startPing(this);
@@ -1394,6 +1402,10 @@ void Channel::createWebsocket(void *att) {
        }
        n = 0;
        get_ip_port_from_uri(uri, &server_ip_address, &server_port);
+
+       if (server_ip_address == "127.0.0.1") {
+               isLocalChannel = true;
+       }
        string api = getapifromUri(uri);
        api.append("channels/").append(ChannelID);
 
@@ -1684,7 +1696,7 @@ void ChannelConnectionHandler::startPing(Channel *ptr) {
        channel_ptr = ptr;
 
        if (pingpongTimer <= 0) {
-               pingpongTimer = startTimer(__send_ping_pong, __timeout_worker, pingTimeout/1000, ptr);
+               pingpongTimer = startTimer(__send_ping_pong, __timeout_worker, pingTimeout, ptr);
        }
 }
 
@@ -1695,7 +1707,7 @@ void ChannelConnectionHandler::__send_ping_pong(void* data)
        long now = time(0);
 
        if (now > ptr->connectionHandler->lastPingReceived +
-                               ptr->connectionHandler->pingTimeout) {
+                               ptr->connectionHandler->pingTimeout/1000) {
                MSF_DBG("## Pinging timeout. disconnect ###");
                ptr->disconnect();
        } else {
@@ -1707,7 +1719,7 @@ void ChannelConnectionHandler::__send_ping_pong(void* data)
                stopTimer(ptr->connectionHandler->pingpongTimer);
                ptr->connectionHandler->pingpongTimer = 0;
        }
-       ptr->connectionHandler->pingpongTimer = startTimer(__send_ping_pong, __timeout_worker, ptr->connectionHandler->pingTimeout/1000, ptr);
+       ptr->connectionHandler->pingpongTimer = startTimer(__send_ping_pong, __timeout_worker, ptr->connectionHandler->pingTimeout, ptr);
 }
 
 int ChannelConnectionHandler::startTimer(timer_function function, TimerWorker woker, unsigned int interval, void *data)