X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=libubus.c;h=0a0df973b6276000f06a2950b0f38af0339c2758;hp=1ebc4214403e705d0f5c3d8d2476e2c3eb023836;hb=fb45e383c2985c43a9aaf42050fef039473745ce;hpb=12a8f978cb91dcc24a23a31fe3cdbbb0e5efad96 diff --git a/libubus.c b/libubus.c index 1ebc421..0a0df97 100644 --- a/libubus.c +++ b/libubus.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -71,6 +72,38 @@ out: return err; } +static int writev_retry(int fd, struct iovec *iov, int iov_len) +{ + int len = 0; + + do { + int cur_len = writev(fd, iov, iov_len); + if (cur_len < 0) { + switch(errno) { + case EAGAIN: + /* turn off non-blocking mode */ + fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & + ~O_NONBLOCK); + break; + case EINTR: + break; + default: + return -1; + } + continue; + } + len += cur_len; + while (cur_len >= iov->iov_len) { + cur_len -= iov->iov_len; + iov_len--; + iov++; + if (!cur_len || !iov_len) + return len; + } + iov->iov_len -= cur_len; + } while (1); +} + static int ubus_send_msg(struct ubus_context *ctx, uint32_t seq, struct blob_attr *msg, int cmd, uint32_t peer) { @@ -92,7 +125,7 @@ static int ubus_send_msg(struct ubus_context *ctx, uint32_t seq, iov[1].iov_base = (char *) msg; iov[1].iov_len = blob_raw_len(msg); - return writev(ctx->sock.fd, iov, 2); + return writev_retry(ctx->sock.fd, iov, ARRAY_SIZE(iov)); } static int ubus_start_request(struct ubus_context *ctx, struct ubus_request *req, @@ -732,10 +765,8 @@ int ubus_register_event_handler(struct ubus_context *ctx, if (pattern) blobmsg_add_string(&b2, "pattern", pattern); - ret = ubus_invoke(ctx, UBUS_SYSTEM_OBJECT_EVENT, "register", b2.head, + return ubus_invoke(ctx, UBUS_SYSTEM_OBJECT_EVENT, "register", b2.head, NULL, NULL); - - return 0; } int ubus_send_event(struct ubus_context *ctx, const char *id,