Add EAGAIN/EWOULDBLOCK error handling 24/91524/3 accepted/tizen/3.0/ivi/20161028.122947 accepted/tizen/3.0/mobile/20161028.122222 accepted/tizen/3.0/tv/20161028.122521 accepted/tizen/3.0/wearable/20161028.122736 accepted/tizen/common/20161010.145842 accepted/tizen/ivi/20161010.083240 accepted/tizen/mobile/20161010.083148 accepted/tizen/tv/20161010.083208 accepted/tizen/wearable/20161010.083222 submit/tizen/20161010.043049 submit/tizen_3.0/20161028.062323 submit/tizen_3.0/20161028.082323 submit/tizen_3.0_common/20161104.104000
authorHyunho Kang <hhstark.kang@samsung.com>
Mon, 10 Oct 2016 05:22:23 +0000 (14:22 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Mon, 10 Oct 2016 05:52:49 +0000 (14:52 +0900)
- wrt(nodejs) can change blocking socket to none blocking socket

Change-Id: I1846a58aaf14f391558bbe404542990d373d072a
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
src/message-port.c

index eb86b2f82ca686d06a58831dd6144e12932521ed..995df34be8d96ed6a1a45353c1485dd1e32c5c49 100755 (executable)
@@ -50,7 +50,7 @@
 #define DBUS_RELEASE_NAME_REPLY_NON_EXISTENT    2 /* *< The given name does not exist on the bus */
 #define DBUS_RELEASE_NAME_REPLY_NOT_OWNER       3 /* *< Service is not an owner of the given name */
 #define HEADER_LEN 8
-#define MAX_RETRY_CNT 2
+#define MAX_RETRY_CNT 10
 #define SOCK_PAIR_SENDER 0
 #define SOCK_PAIR_RECEIVER 1
 
@@ -593,6 +593,7 @@ static int __read_socket(int fd,
        unsigned int left = nbytes;
        ssize_t nb;
        int retry_cnt = 0;
+       const struct timespec TRY_SLEEP_TIME = { 0, 500 * 1000 * 1000 };
 
        *bytes_read = 0;
        while (left && (retry_cnt < MAX_RETRY_CNT)) {
@@ -601,9 +602,11 @@ static int __read_socket(int fd,
                        LOGE("__read_socket: ...read EOF, socket closed %d: nb %d\n", fd, nb);
                        return MESSAGEPORT_ERROR_IO_ERROR;
                } else if (nb == -1) {
-                       if (errno == EINTR) {
-                               LOGE("__read_socket: EINTR error continue ...");
+                       /*  wrt(nodejs) could change socket to none-blocking socket :-( */
+                       if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
+                               LOGE("__read_socket: %d errno, sleep and retry ...", errno);
                                retry_cnt++;
+                               nanosleep(&TRY_SLEEP_TIME, 0);
                                continue;
                        }
                        LOGE("__read_socket: ...error fd %d: errno %d\n", fd, errno);