Use buxton_errno instead of global variable 'errno' 60/217860/2
authorJusung Son <jusung07.son@samsung.com>
Fri, 15 Nov 2019 04:03:56 +0000 (13:03 +0900)
committerJusung Son <jusung07.son@samsung.com>
Fri, 15 Nov 2019 05:04:51 +0000 (14:04 +0900)
Change-Id: I74d1a072f42b169aa1991420233f1c7c07c3b2ee
Signed-off-by: Jusung Son <jusung07.son@samsung.com>
common/proto.c
daemon/daemon.c

index ac4d1b0..152d131 100644 (file)
@@ -30,6 +30,7 @@
 #include "proto.h"
 
 #define SEND_TIMEOUT 1000 /* milliseconds */
+#define MAX_RETRY_CNT 5
 
 struct recv_info {
        int fd;
@@ -386,6 +387,7 @@ int proto_send(int fd, enum message_type type, uint8_t *data, int32_t len)
        struct header *hdr;
        uint8_t *buf;
        struct pollfd fds[1];
+       int retry_cnt = 0;
 
        if (!data || len <= 0 || fd < 0) {
                bxt_err("Invalid parameter");
@@ -435,12 +437,29 @@ int proto_send(int fd, enum message_type type, uint8_t *data, int32_t len)
                } while (r < 0);
        }
 
-       r = send(fd, buf, sizeof(*hdr) + len, MSG_NOSIGNAL);
+        while(retry_cnt < MAX_RETRY_CNT) {
+               r = send(fd, buf, sizeof(*hdr) + len, MSG_NOSIGNAL);
+               if (r == -1) {
+                       if (errno == EINTR) {
+                               retry_cnt++;
+                               continue;
+                       }
 
-       free(buf);
+                       r = errno;
+                       bxt_err("send: fd %d errno %d", fd, r);
+                       free(buf);
+
+                       if (r == EWOULDBLOCK || r == EAGAIN)
+                               return BUXTON_ERROR_TIME_OUT; /* Returns  BUXTON_ERROR_TIME_OUT to retry */
 
-       if (r == -1) {
-               bxt_err("send: fd %d errno %d", fd, errno);
+                       return BUXTON_ERROR_IO_ERROR;
+               }
+               break;
+       }
+
+       free(buf);
+       if(retry_cnt >= MAX_RETRY_CNT) {
+               bxt_err("send: fd %d retry_cnt %d", fd, retry_cnt);
                return BUXTON_ERROR_IO_ERROR;
        }
 
index 87c9bd7..903bfd6 100644 (file)
@@ -253,18 +253,16 @@ static gboolean _send_notis(gpointer key, gpointer value, gpointer data)
        _data = g_base64_decode(g_data, &_len);
 
        r = proto_send(cli->fd, MSG_NOTI, (uint8_t *)_data, (int)_len);
+       free(_data);
        if (r != BUXTON_ERROR_NONE) {
-               bxt_err("send noti again key : %s pid : %d errno : %d",
-                               (char *)key, cli->cred.pid, errno);
-               if (errno == EWOULDBLOCK || errno == EAGAIN) {
-                       free(_data);
+               bxt_err("send noti again key : %s pid : %d return value : %d",
+                               (char *)key, cli->cred.pid, r);
+               if (r == BUXTON_ERROR_TIME_OUT)
                        return FALSE;
-               }
+       } else {
+               _write_file_log(LOG_SEND_DELAYED_NOTI, cli, NULL);
        }
 
-       _write_file_log(LOG_SEND_DELAYED_NOTI, cli, NULL);
-
-       free(_data);
        return TRUE;
 }
 
@@ -321,8 +319,8 @@ static void send_notis(struct bxt_daemon *bxtd, struct request *rqst)
                r = proto_send(cli->fd, req.type, data, len);
                if (r != BUXTON_ERROR_NONE) {
                        bxt_err("send notis: cli pid : %d  label : %s key : %s error %d",
-                                       cli->cred.pid, cli->label, rqst->key, errno);
-                       if (errno == EWOULDBLOCK || errno == EAGAIN) {
+                                       cli->cred.pid, cli->label, rqst->key, r);
+                       if (r == BUXTON_ERROR_TIME_OUT) {
                                _data = g_base64_encode(data, len);
 
                                if (cli->fd_out_id == 0) {