From 765bc0c10fd3abdec175583ecef79350c04cdf14 Mon Sep 17 00:00:00 2001 From: Sudipto Date: Fri, 1 Feb 2019 16:44:43 +0530 Subject: [PATCH 1/1] Fix for unlimited attepmts to write to socket Change-Id: Id90bebe5d40f1ac599d996e3e2da66217391a9eb Signed-off-by: Sudipto --- bt-api/bt-rfcomm-client.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bt-api/bt-rfcomm-client.c b/bt-api/bt-rfcomm-client.c index 4c0b4c9..888f562 100644 --- a/bt-api/bt-rfcomm-client.c +++ b/bt-api/bt-rfcomm-client.c @@ -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("-"); -- 2.7.4