client wait time checking addition 84/210484/2 accepted/tizen/unified/20190724.063734 submit/tizen/20190722.090702
authorSameer Prakash Pradhan <sp.pradhan@samsung.com>
Fri, 19 Jul 2019 10:29:57 +0000 (15:59 +0530)
committerSameer Prakash Pradhan <sp.pradhan@samsung.com>
Mon, 22 Jul 2019 06:19:14 +0000 (11:49 +0530)
Signed-off-by: Sameer Prakash Pradhan <sp.pradhan@samsung.com>
Change-Id: Ib0d934a8660f48c2c4e0619194b565dcd937f415

src/pims-socket.c

index d54b31a..ff8d403 100644 (file)
@@ -37,6 +37,7 @@
 
 #define MAX_ARRAY_LEN 65535
 #define PIMS_WAIT_MSEC 4500
+#define PIMS_RECVWAIT_MSEC 5000
 
 static int _get_pid(int fd)
 {
@@ -113,7 +114,7 @@ int socket_send(int fd, char *buf, int len)
                                        int diff_msec = _sub_timespec_in_msec(&st);
                                        if (PIMS_WAIT_MSEC < diff_msec) {
                                                ERR("EAGAIN error. send retry: errno[%d]", errno);
-                                               DBG("send timestamp (%ld.%ld)sec and wait (%d)msec", st.tv_sec, st.tv_nsec, diff_msec);
+                                               ERR("send timestamp (%ld.%ld)sec and wait (%d)msec", st.tv_sec, st.tv_nsec, diff_msec);
                                                int pid = _get_pid(fd);
                                                if (true == _is_send_block(fd)) {
                                                        DBG("send blocked. kill fd(%d) pid(%d)", fd, pid);
@@ -157,15 +158,30 @@ int socket_recv(int fd, void **buf, unsigned int len)
 
        RETV_IF(NULL == *buf, -1);
 
+       bool retry = false;
+       struct timespec st = {0};
+
        while (length > 0) {
                read_len = read(fd, (void *)temp, length);
                if (read_len < 0) {
-                       if (errno == EINTR)
-                               continue;
-                       else if (errno == EAGAIN)
+                       if (errno == EINTR) {
                                continue;
-                       else if (errno == EWOULDBLOCK)
+                       } else if (errno == EAGAIN) { /* same as EWOULDBLOCK */
+                               if (false == retry) {
+                                       clock_gettime(CLOCK_MONOTONIC, &st);
+                                       retry = true;
+                               } else {
+                                       int diff_msec = _sub_timespec_in_msec(&st);
+                                       if (PIMS_RECVWAIT_MSEC < diff_msec) {
+                                               ERR("error! (%d) connection will be closed by timeout!", errno);
+                                               ERR("send timestamp (%ld.%ld)sec and wait (%d)msec", st.tv_sec, st.tv_nsec, diff_msec);
+                                               free(*buf);
+                                               *buf = NULL;
+                                               return -1;
+                                       }
+                               }
                                continue;
+                       }
                        else if (errno == EPIPE) {
                                ERR("connection closed : read err %d, read_lenn %d, length %u", errno, read_len, length);
                                free(*buf);