From: Senthil Kumar G S Date: Thu, 31 Oct 2019 05:04:42 +0000 (+0530) Subject: Set error code to 0 for normal TCP disconnection. X-Git-Tag: submit/tizen/20191119.000236~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=37f3677ca981461ff80f0d66dbd23a166442edb0;p=platform%2Fupstream%2Fiotivity.git Set error code to 0 for normal TCP disconnection. g_lastErrorCode is set to 0 to indicate normal session disconnections(recv() returns 0). Background; "g_lastErrorCode" is being set as errno when send() returns -1 or recv() returns under 0. For instance, in case of recv(), - normal TCP session disconnect happens when recv() returns 0 len. - abnormal TCP session disconnect happens when recv() returns under 0. ( "g_lastErrorCode" is set as errno. ) Let's guess this scenario, - abnormal TCP session disconnect => "g_lastErrorCode" is set as X => ...... => retry TCP session connect => ...... => normal TCP session disconnect From above scenario, then, is "g_lastErrorCode" not changed to default value 0? I think, it is needed to set "g_lastErrorCode" as default value 0 when normal TCP session connect/disconnect happens. https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/595/commits/db79794eab8a1dbbe93d2da4a5deeb4826e22ccb (cherry-picked from db79794eab8a1dbbe93d2da4a5deeb4826e22ccb) Change-Id: Iea0d2ed780b9dedee6870a8946c3c5c65d15757c Signed-off-by: Senthil Kumar G S Signed-off-by: Sudipto Bal --- diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c index 1a1702a19..f0ca652d8 100755 --- a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c @@ -131,6 +131,7 @@ static CATCPConnectionHandleCallback g_connectionCallback = NULL; /** * Error code to hold the errno(Timeout, Destination unreachable, etc) when send/recv fails. * Main purpose is to hold the reason for connection drop when keep-alive is in use. + * To indicate normal disconnection, 0 will be assigned. */ static int g_lastErrorCode; @@ -750,11 +751,13 @@ static void CAReceiveMessage(int fd) { g_lastErrorCode = errno; OIC_LOG_V(DEBUG, TAG, "Set g_lastErrorCode to %s", strerror(g_lastErrorCode)); - OIC_LOG_V(ERROR, TAG, "recv failed %s", strerror(errno)); + OIC_LOG_V(ERROR, TAG, "recv failed %s", strerror(g_lastErrorCode)); res = CA_RECEIVE_FAILED; } else if (0 == len) { + g_lastErrorCode = 0; + OIC_LOG(DEBUG, TAG, "Set g_lastErrorCode to 0"); OIC_LOG(INFO, TAG, "Received disconnect from peer. Close connection"); svritem->state = DISCONNECTED; res = CA_DESTINATION_DISCONNECTED; @@ -804,11 +807,13 @@ static void CAReceiveMessage(int fd) { g_lastErrorCode = errno; OIC_LOG_V(DEBUG, TAG, "Set g_lastErrorCode to %s", strerror(g_lastErrorCode)); - OIC_LOG_V(ERROR, TAG, "recv failed %s", strerror(errno)); + OIC_LOG_V(ERROR, TAG, "recv failed %s", strerror(g_lastErrorCode)); res = CA_RECEIVE_FAILED; } else if (0 == len) { + g_lastErrorCode = 0; + OIC_LOG_V(DEBUG, TAG, "Set g_lastErrorCode to 0"); OIC_LOG(INFO, TAG, "Received disconnect from peer. Close connection"); res = CA_DESTINATION_DISCONNECTED; } @@ -1511,11 +1516,11 @@ static ssize_t sendData(const CAEndpoint_t *endpoint, const void *data, { g_lastErrorCode = errno; OIC_LOG_V(DEBUG, TAG, "Set g_lastErrorCode to %s", strerror(g_lastErrorCode)); - if (EWOULDBLOCK != errno && EAGAIN != errno) + if (EWOULDBLOCK != g_lastErrorCode && EAGAIN != g_lastErrorCode) { - OIC_LOG_V(ERROR, TAG, "unicast ipv4tcp sendTo failed: %s", strerror(errno)); + OIC_LOG_V(ERROR, TAG, "unicast ipv4tcp sendTo failed: %s", strerror(g_lastErrorCode)); CALogSendStateInfo(endpoint->adapter, endpoint->addr, endpoint->port, - len, false, strerror(errno)); + len, false, strerror(g_lastErrorCode)); return len; }