X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=ubusd.c;h=ba1ff07720fa3da7cf5576eecfddc1c9530ba391;hp=7279a706f47e44caf92d5433326b5b733bb1b440;hb=HEAD;hpb=5dfd3c16fa1cc9e288c41ef6e3e4c3bc63acf612;ds=sidebyside diff --git a/ubusd.c b/ubusd.c index 7279a70..ba1ff07 100644 --- a/ubusd.c +++ b/ubusd.c @@ -32,8 +32,15 @@ static struct ubus_msg_buf *ubus_msg_ref(struct ubus_msg_buf *ub) { - if (ub->refcount == ~0) - return ubus_msg_new(ub->data, ub->len, false); + struct ubus_msg_buf *new_ub; + if (ub->refcount == ~0) { + new_ub = ubus_msg_new(ub->data, ub->len, false); + if (!new_ub) + return NULL; + memcpy(&new_ub->hdr, &ub->hdr, sizeof(struct ubus_msghdr)); + new_ub->fd = ub->fd; + return new_ub; + } ub->refcount++; return ub; @@ -139,7 +146,7 @@ static void ubus_msg_enqueue(struct ubus_client *cl, struct ubus_msg_buf *ub) } /* takes the msgbuf reference */ -void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free) +void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub) { int written; @@ -148,22 +155,19 @@ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free) if (!cl->tx_queue[cl->txq_cur]) { written = ubus_msg_writev(cl->sock.fd, ub, 0); - if (written >= ub->len + sizeof(ub->hdr)) - goto out; if (written < 0) written = 0; + if (written >= ub->len + sizeof(ub->hdr)) + return; + cl->txq_ofs = written; /* get an event once we can write to the socket again */ uloop_fd_add(&cl->sock, ULOOP_READ | ULOOP_WRITE | ULOOP_EDGE_TRIGGER); } ubus_msg_enqueue(cl, ub); - -out: - if (free) - ubus_msg_free(ub); } static struct ubus_msg_buf *ubus_msg_head(struct ubus_client *cl)