diff options
| author | Felix Fietkau | 2024-04-04 18:45:16 +0000 |
|---|---|---|
| committer | Felix Fietkau | 2024-04-04 18:45:18 +0000 |
| commit | ddb18d2657578bb39ffad4795cedee215f9b36b0 (patch) | |
| tree | 46ea74d5c76f0b32f3f537b0e5dd455b0041d0e9 | |
| parent | e611e6d0ff0ba31070abacdb53037d3e9a4115a6 (diff) | |
| download | uclient-ddb18d2657578bb39ffad4795cedee215f9b36b0.tar.gz | |
uclient: add function for getting the amount of pending read/write data
This can be used to throttle writes when doing large POST requests
Signed-off-by: Felix Fietkau <nbd@nbd.name>
| -rw-r--r-- | uclient-backend.h | 1 | ||||
| -rw-r--r-- | uclient-http.c | 9 | ||||
| -rw-r--r-- | uclient.c | 8 | ||||
| -rw-r--r-- | uclient.h | 1 |
4 files changed, 19 insertions, 0 deletions
diff --git a/uclient-backend.h b/uclient-backend.h index b013cde..1b808ac 100644 --- a/uclient-backend.h +++ b/uclient-backend.h @@ -34,6 +34,7 @@ struct uclient_backend { int (*read)(struct uclient *cl, char *buf, unsigned int len); int (*write)(struct uclient *cl, const char *buf, unsigned int len); + int (*pending_bytes)(struct uclient *cl, bool write); }; void uclient_backend_set_error(struct uclient *cl, int code); diff --git a/uclient-http.c b/uclient-http.c index 33f6513..d6e9dcf 100644 --- a/uclient-http.c +++ b/uclient-http.c @@ -1229,6 +1229,14 @@ int uclient_http_set_address_family(struct uclient *cl, int af) return 0; } +static int +uclient_http_pending_bytes(struct uclient *cl, bool write) +{ + struct uclient_http *uh = container_of(cl, struct uclient_http, uc); + + return ustream_pending_data(uh->us, write); +} + const struct uclient_backend uclient_backend_http = { .prefix = uclient_http_prefix, @@ -1242,4 +1250,5 @@ const struct uclient_backend uclient_backend_http = { .read = uclient_http_read, .write = uclient_http_send_data, .request = uclient_http_request_done, + .pending_bytes = uclient_http_pending_bytes, }; @@ -406,6 +406,14 @@ int uclient_read(struct uclient *cl, char *buf, int len) return cl->backend->read(cl, buf, len); } +int uclient_pending_bytes(struct uclient *cl, bool write) +{ + if (!cl->backend->pending_bytes) + return -1; + + return cl->backend->pending_bytes(cl, write); +} + void uclient_disconnect(struct uclient *cl) { uloop_timeout_cancel(&cl->connection_timeout); @@ -113,6 +113,7 @@ void uclient_disconnect(struct uclient *cl); int uclient_read(struct uclient *cl, char *buf, int len); int uclient_write(struct uclient *cl, const char *buf, int len); +int uclient_pending_bytes(struct uclient *cl, bool write); int uclient_request(struct uclient *cl); char *uclient_get_addr(char *dest, int *port, union uclient_addr *a); |