From eaa08d73ab735e4008762020c8b54b741411528d Mon Sep 17 00:00:00 2001 From: Suchang Woo Date: Fri, 14 Aug 2015 19:18:56 +0900 Subject: [PATCH] common: set send timeout If the receiver is blocked, Buxton daemon also can be blocked. To prevent blocking, timeout argument in poll() is set. Change-Id: I42cc6d8ba18cffebdc9eac6bab74bf3f56ecf24f Signed-off-by: Suchang Woo --- common/proto.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/common/proto.c b/common/proto.c index ae9a06a..0246640 100644 --- a/common/proto.c +++ b/common/proto.c @@ -29,6 +29,8 @@ #include "log.h" #include "proto.h" +#define SEND_TIMEOUT 1000 /* milliseconds */ + struct recv_info { int fd; uint16_t seq; @@ -381,8 +383,7 @@ int proto_send(int fd, enum message_type type, uint8_t *data, int32_t len) fds[0].revents = 0; do { - /* CAN BE BLOCKED ! */ - r = poll(fds, 1, -1); + r = poll(fds, 1, SEND_TIMEOUT); if (r == -1) { if (errno == EINTR) continue; @@ -392,7 +393,15 @@ int proto_send(int fd, enum message_type type, uint8_t *data, int32_t len) return -1; } - } while (r <= 0); + + if (r == 0) { + bxt_err("send: fd %d poll timeout", fd); + free(buf); + errno = ETIMEDOUT; + + return -1; + } + } while (r < 0); r = send(fd, buf, sizeof(*hdr) + len, 0); -- 2.7.4