Fix for unlimited attepmts to write to socket 30/199130/2
authorSudipto <sudipto.bal@samsung.com>
Fri, 1 Feb 2019 11:14:43 +0000 (16:44 +0530)
committerSudipto <sudipto.bal@samsung.com>
Thu, 7 Feb 2019 09:29:54 +0000 (14:59 +0530)
Change-Id: Id90bebe5d40f1ac599d996e3e2da66217391a9eb
Signed-off-by: Sudipto <sudipto.bal@samsung.com>
bt-api/bt-rfcomm-client.c

index 4c0b4c9..888f562 100644 (file)
@@ -1287,7 +1287,7 @@ BT_EXPORT_API int bluetooth_rfcomm_disconnect(int socket_fd)
 #else
 static int __write_all(int fd, const char *buf, int len)
 {
-       int sent = 0;
+       int sent = 0, try = 0;
 
        BT_DBG("+");
        while (len > 0) {
@@ -1296,8 +1296,11 @@ static int __write_all(int fd, const char *buf, int len)
                written = write(fd, buf, len);
                BT_DBG("written: %d", written);
                if (written < 0) {
-                       if (errno == EINTR || errno == EAGAIN)
-                               continue;
+                       if (errno == EINTR || errno == EAGAIN) {
+                               try++;
+                               if (try <= 49)
+                                       continue;
+                       }
                        return -1;
                }
 
@@ -1307,6 +1310,7 @@ static int __write_all(int fd, const char *buf, int len)
                len -= written;
                buf += written;
                sent += written;
+               try = 0;
        }
 
        BT_DBG("-");