[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] [PATCH] evhttp getting connection's output buffer length



Hello,

I'm using libevent in a streaming application. Because in a streaming
scenario content length is infinite I have to check how much data is
queued per client and disconnect ones that aren't able to fetch data
due to throughput issues (MPEG streaming). As far as I checked evhttp
doesn't provide a way to get connection's output buffer length.

checking length of evhttp_request_get_output_buffer gives a buffer of
zero length after sending data through evhttp_send_reply_chunk

One has to get into connection's bufferevent output buffer.
Below is a sample usage of an added API call that works for me.

Please consider adding it or writing something similar. I had doubts
if this API call should return buffer length or the buffer itself and
user should check it's length.


       evhttp_send_reply_chunk(hr->req, hr->evbuffer);
       struct evhttp_connection *conn;
       conn = evhttp_request_get_connection(hr->req);
       dprintf("obuff len: %d\n",
evhttp_connection_get_output_buffer_length(conn));


Patch:

diff --git a/http.c b/http.c
index 575623a..4bc04b3 100644
--- a/http.c
+++ b/http.c
@@ -3472,6 +3472,12 @@ evhttp_connection_get_base(struct
evhttp_connection *conn)
       return conn->base;
 }

+size_t
+evhttp_connection_get_output_buffer_length(struct evhttp_connection *conn)
+{
+               return evbuffer_get_length(bufferevent_get_output(conn->bufev));
+}
+
 void
 evhttp_request_set_chunked_cb(struct evhttp_request *req,
    void (*cb)(struct evhttp_request *, void *))
diff --git a/include/event2/http.h b/include/event2/http.h
index 793e2b8..d12de5d 100644
--- a/include/event2/http.h
+++ b/include/event2/http.h
@@ -459,6 +459,12 @@ struct evhttp_connection
*evhttp_request_get_connection(struct evhttp_request *r
 */
 struct event_base *evhttp_connection_get_base(struct evhttp_connection *req);

+/**
+ * Returns length of connection's output buffer
+ */
+size_t evhttp_connection_get_output_buffer_length(struct
evhttp_connection *req);
+
+
 void evhttp_connection_set_max_headers_size(struct evhttp_connection *evcon,
    ev_ssize_t new_max_headers_size);

-- 
.: Jakub Paweł Głazik,
.: email & jabber: zytek<at>nuxi.pl
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.