common: set send timeout 86/46086/1
authorSuchang Woo <suchang.woo@samsung.com>
Fri, 14 Aug 2015 10:18:56 +0000 (19:18 +0900)
committerSuchang Woo <suchang.woo@samsung.com>
Fri, 14 Aug 2015 10:26:08 +0000 (19:26 +0900)
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 <suchang.woo@samsung.com>
common/proto.c

index ae9a06a..0246640 100644 (file)
@@ -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);