X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=libubus-io.c;h=55ddff5f62e47ddbb5ce428c2111a85a2fa52d01;hp=f38403f83b9eef1ff1259778bc7b5cb02d0fdec1;hb=3e45a782b22c067eab125b377474f5da11eabbe9;hpb=82da9db3a985a53c73a21e0fda92a4a59d176f71 diff --git a/libubus-io.c b/libubus-io.c index f38403f..55ddff5 100644 --- a/libubus-io.c +++ b/libubus-io.c @@ -111,7 +111,10 @@ static int writev_retry(int fd, struct iovec *iov, int iov_len, int sock_fd) if (!iov_len) return len; } + iov->iov_base += cur_len; iov->iov_len -= cur_len; + msghdr.msg_iov = iov; + msghdr.msg_iovlen = iov_len; } while (1); /* Should never reach here */ @@ -251,15 +254,11 @@ static bool get_next_msg(struct ubus_context *ctx, int *recv_fd) return false; len = blob_raw_len(&hdrbuf.data); - if (len > ctx->msgbuf_data_len) { + if (len > ctx->msgbuf_data_len) ctx->msgbuf_reduction_counter = UBUS_MSGBUF_REDUCTION_INTERVAL; - } else if (ctx->msgbuf_data_len > UBUS_MSG_CHUNK_SIZE) { - if (ctx->msgbuf_reduction_counter > 0) { - len = -1; - --ctx->msgbuf_reduction_counter; - } else - len = UBUS_MSG_CHUNK_SIZE; - } else + else if (ctx->msgbuf_reduction_counter > 0 && len < UBUS_MSG_CHUNK_SIZE) + len = !--ctx->msgbuf_reduction_counter ? UBUS_MSG_CHUNK_SIZE : -1; + else len = -1; if (len > -1) { @@ -284,11 +283,10 @@ static bool get_next_msg(struct ubus_context *ctx, int *recv_fd) void __hidden ubus_handle_data(struct uloop_fd *u, unsigned int events) { struct ubus_context *ctx = container_of(u, struct ubus_context, sock); - struct ubus_msghdr *hdr = &ctx->msgbuf.hdr; int recv_fd = -1; while (get_next_msg(ctx, &recv_fd)) { - ubus_process_msg(ctx, hdr, recv_fd); + ubus_process_msg(ctx, &ctx->msgbuf, recv_fd); if (uloop_cancelled) break; } @@ -376,7 +374,7 @@ int ubus_reconnect(struct ubus_context *ctx, const char *path) goto out_free; ret = UBUS_STATUS_OK; - fcntl(ctx->sock.fd, F_SETFL, fcntl(ctx->sock.fd, F_GETFL) | O_NONBLOCK); + fcntl(ctx->sock.fd, F_SETFL, fcntl(ctx->sock.fd, F_GETFL) | O_NONBLOCK | O_CLOEXEC); ubus_refresh_state(ctx);