ubusd: add per-client tx queue limit
No new message can be enqueued if this brings the total queue length of that client over UBUS_CLIENT_MAX_TXQ_LEN. Set UBUS_CLIENT_MAX_TXQ_LEN to UBUS_MAX_MSGLEN, i.e. 1MB. This limit should be plenty for any practical use case. Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
This commit is contained in:
parent
4becbd67de
commit
c736e47f3e
3 changed files with 8 additions and 0 deletions
5
ubusd.c
5
ubusd.c
|
@ -144,6 +144,9 @@ static void ubus_msg_enqueue(struct ubus_client *cl, struct ubus_msg_buf *ub)
|
||||||
{
|
{
|
||||||
struct ubus_msg_buf_list *ubl;
|
struct ubus_msg_buf_list *ubl;
|
||||||
|
|
||||||
|
if (cl->txq_len + ub->len > UBUS_CLIENT_MAX_TXQ_LEN)
|
||||||
|
return;
|
||||||
|
|
||||||
ubl = calloc(1, sizeof(struct ubus_msg_buf_list));
|
ubl = calloc(1, sizeof(struct ubus_msg_buf_list));
|
||||||
if (!ubl)
|
if (!ubl)
|
||||||
return;
|
return;
|
||||||
|
@ -152,6 +155,7 @@ static void ubus_msg_enqueue(struct ubus_client *cl, struct ubus_msg_buf *ub)
|
||||||
ubl->msg = ubus_msg_ref(ub);
|
ubl->msg = ubus_msg_ref(ub);
|
||||||
|
|
||||||
list_add_tail(&cl->tx_queue, &ubl->list);
|
list_add_tail(&cl->tx_queue, &ubl->list);
|
||||||
|
cl->txq_len += ub->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* takes the msgbuf reference */
|
/* takes the msgbuf reference */
|
||||||
|
@ -172,6 +176,7 @@ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cl->txq_ofs = written;
|
cl->txq_ofs = written;
|
||||||
|
cl->txq_len = -written;
|
||||||
|
|
||||||
/* get an event once we can write to the socket again */
|
/* get an event once we can write to the socket again */
|
||||||
uloop_fd_add(&cl->sock, ULOOP_READ | ULOOP_WRITE | ULOOP_EDGE_TRIGGER);
|
uloop_fd_add(&cl->sock, ULOOP_READ | ULOOP_WRITE | ULOOP_EDGE_TRIGGER);
|
||||||
|
|
2
ubusd.h
2
ubusd.h
|
@ -24,6 +24,7 @@
|
||||||
#include "ubusd_acl.h"
|
#include "ubusd_acl.h"
|
||||||
|
|
||||||
#define UBUS_OBJ_HASH_BITS 4
|
#define UBUS_OBJ_HASH_BITS 4
|
||||||
|
#define UBUS_CLIENT_MAX_TXQ_LEN UBUS_MAX_MSGLEN
|
||||||
|
|
||||||
extern struct blob_buf b;
|
extern struct blob_buf b;
|
||||||
|
|
||||||
|
@ -54,6 +55,7 @@ struct ubus_client {
|
||||||
|
|
||||||
struct list_head tx_queue;
|
struct list_head tx_queue;
|
||||||
unsigned int txq_ofs;
|
unsigned int txq_ofs;
|
||||||
|
unsigned int txq_len;
|
||||||
|
|
||||||
struct ubus_msg_buf *pending_msg;
|
struct ubus_msg_buf *pending_msg;
|
||||||
struct ubus_msg_buf *retmsg;
|
struct ubus_msg_buf *retmsg;
|
||||||
|
|
|
@ -74,6 +74,7 @@ static void client_cb(struct uloop_fd *sock, unsigned int events)
|
||||||
}
|
}
|
||||||
|
|
||||||
cl->txq_ofs += written;
|
cl->txq_ofs += written;
|
||||||
|
cl->txq_len -= written;
|
||||||
if (cl->txq_ofs < ub->len + sizeof(ub->hdr))
|
if (cl->txq_ofs < ub->len + sizeof(ub->hdr))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue