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

Re: [Libevent-users] Handling concurent evhttp connections with evhttp_send_reply_chunk.



Dnia 2009-11-17, wto o godzinie 04:21 +0200, Tero Marttila pisze:
> One option is to add the functionality to evhttp.
So there is no existing functionality for this, right?

> I don't have any concrete patches to post, but when I tried this a 
> (long) while ago, it was fairly straightforward, just building on top of 
> the existing bufferevent watermark functionality.
I'm libevent newbie so it's not so easy for me. But maybe if you would
help me a little i would be able to do this..

> 
> More specifically, it amounted to having evhttp_write_buffer apply a 
> suitable bufferevent_setwatermark (EV_WRITE lowmark) when called from 
> within evhttp_send_reply_chunk, setting up evcon->cb to invoke the 
> user's "send more data" callback from evhttp_write_cb. This worked, to 
> the extent that I tested it.
I'm not sure how exactly bufferevent_setwatermark is supposed to work.
If I understand this correctly, it will ensure that evhttp_write_cb
won't be called untill write buffer is empty (or almost empty) or when
it's full. Is this right?

And how should user's "send more data" callback be registered. You mean
something like the following?

--- libevent-2.0.2-alpha.orig/http.c    2009-05-15 08:40:58.000000000+0200
+++ libevent-2.0.2-alpha/http.c 2009-11-17 15:47:00.000000000 +0100
@@ -2025,8 +2025,23 @@
        evhttp_write_buffer(req->evcon, NULL, NULL);
 }
 
+struct evhttp_chunk_args
+{
+       struct evhttp_request *req;
+       void (*cb)(struct evhttp_request *, void *);
+       void *arg;
+};
+
+static void
+evhttp_send_reply_chunk_cb(struct evhttp_connection *evcon, void *arg)
+{
+       struct evhttp_chunk_args *args=arg;
+       if(args->cb) 
+               (*args->cb)(args->req, args->arg);
+}
+
 void
-evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf)
+evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf, void(*cb)(struct evhttp_request *, void *), void *arg)
 {
        struct evbuffer *output = bufferevent_get_output(req->evcon->bufev);
        if (evbuffer_get_length(databuf) == 0)
@@ -2041,7 +2056,17 @@
        if (req->chunked) {
                evbuffer_add(output, "\r\n", 2);
        }
-       evhttp_write_buffer(req->evcon, NULL, NULL);
+       if(cb) {
+               struct evhttp_chunk_args *args = malloc(sizeof(struct evhttp_chunk_args));
+               memset(args, 0, sizeof(struct evhttp_chunk_args));
+               args->req=req;
+               args->cb=cb;
+               args->arg=arg;
+               evhttp_write_buffer(req->evcon, evhttp_send_reply_chunk_cb, (void *)args);
+
+       } else {
+               evhttp_write_buffer(req->evcon, NULL, NULL);
+       }
 }
 
 void


***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.