summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJusung Son <jusung07.son@samsung.com>2019-11-15 13:03:56 +0900
committerJusung Son <jusung07.son@samsung.com>2019-11-15 14:04:51 +0900
commitbf77ac5a099cbaaf38633bf9af37a560e331a6f4 (patch)
tree86d5731d844d5691ecf73c9795d8262c7519a216
parent8b2ebe11933cba4ebc1209465adaf2e8be39a649 (diff)
downloadbuxton2-bf77ac5a099cbaaf38633bf9af37a560e331a6f4.tar.gz
buxton2-bf77ac5a099cbaaf38633bf9af37a560e331a6f4.tar.bz2
buxton2-bf77ac5a099cbaaf38633bf9af37a560e331a6f4.zip
Use buxton_errno instead of global variable 'errno'
Change-Id: I74d1a072f42b169aa1991420233f1c7c07c3b2ee Signed-off-by: Jusung Son <jusung07.son@samsung.com>
-rw-r--r--common/proto.c27
-rw-r--r--daemon/daemon.c18
2 files changed, 31 insertions, 14 deletions
diff --git a/common/proto.c b/common/proto.c
index ac4d1b0..152d131 100644
--- a/common/proto.c
+++ b/common/proto.c
@@ -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;
}
diff --git a/daemon/daemon.c b/daemon/daemon.c
index 87c9bd7..903bfd6 100644
--- a/daemon/daemon.c
+++ b/daemon/daemon.c
@@ -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) {