Update snapshot(2017-11-02)
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / tcp_adapter / catcpserver.c
index 16ed703..eaee7f3 100644 (file)
@@ -612,14 +612,10 @@ static void CAReceiveMessage(int fd)
     //disconnect session and clean-up data if any error occurs
     if (res != CA_STATUS_OK)
     {
-#ifdef __WITH_TLS__
-        if (CA_STATUS_OK != CAcloseSslConnection(&svritem->sep.endpoint))
+        if (CA_STATUS_OK != CATCPDisconnectSession(&svritem->sep.endpoint))
         {
-            OIC_LOG(ERROR, TAG, "Failed to close TLS session");
+            OIC_LOG(ERROR, TAG, "Failed to disconnect TCP session");
         }
-#endif
-        CASearchAndDeleteTCPSession(&(svritem->sep.endpoint));
-        return;
     }
 }
 
@@ -1113,20 +1109,27 @@ static ssize_t sendData(const CAEndpoint_t *endpoint, const void *data,
     ssize_t remainLen = dlen;
     do
     {
+        size_t sendCounter = 0;
 #ifdef MSG_NOSIGNAL
-        ssize_t len = send(sockFd, data, remainLen, MSG_NOSIGNAL);
+        ssize_t len = send(sockFd, data, remainLen, MSG_DONTWAIT | MSG_NOSIGNAL);
 #else
-        ssize_t len = send(sockFd, data, remainLen, 0);
+        ssize_t len = send(sockFd, data, remainLen, MSG_DONTWAIT);
 #endif
         if (-1 == len)
         {
-            if (EWOULDBLOCK != errno)
+            if (EWOULDBLOCK != errno && EAGAIN != errno)
             {
                 OIC_LOG_V(ERROR, TAG, "unicast ipv4tcp sendTo failed: %s", strerror(errno));
                 CALogSendStateInfo(endpoint->adapter, endpoint->addr, endpoint->port,
                                    len, false, strerror(errno));
                 return len;
             }
+            sendCounter++;
+            OIC_LOG_V(WARNING, TAG, "send blocked. trying %n attempt from 100", sendCounter);
+            if(sendCounter >= 100)
+            {
+                return len;
+            }
             continue;
         }
         data += len;