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

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



I wouldn't use them for sending large files. Use the good 'ole fashion event_* interfaces for checking when a socket needs more data, and use sendfile() to send the data down the socket when it needs it. No reason to have libevent buffers on top of things for this purpose.

You have basically the same functionality as you would with select(), which means that the "client disconnected" event comes in as a read event but you can't read from it. You could easily call your own callback from the event to handle disconnects.

-Patrick

2009/11/18 Krzysztof Adamski <k@xxxxxxxx>
Dnia 2009-11-18, śro o godzinie 10:40 -0800, Niels Provos pisze:
> On Mon, Nov 16, 2009 at 9:12 AM, Krzysztof Adamski <k@xxxxxxxx> wrote:
> > i would like to build simple HTTPD server using libevent2. It is going
> > to send some quite big files but i would like it to handle couple
> > concurrent connections. The files can be sent in chunks so I'm using
> > evhttp_send_reply_chunk for this. The problem is, how can I send big
> > files while still being able to handle new connections?
>
> The way that chunked connections work at the moment is that you need
> some other event to drive new data being sent to the client.   The
> problem with a single-threaded server is not blocking on the file
> reads.   In libevent-1.4, there is no way to set watermarks or similar
> feedback mechanisms.   However, as we have switched to bufferevents in
> libevent-2.0; this should be possible.
Watermarks seams like a good thing for my case but I just don't accually
know how to use them with evhttp. I would be glad for any details (I'm
libevent newbie and there is not too much of a documentation i could
find, unfortunatly).

> Alternatively, you could read files in a separate process or thread
> and then send data out as it becomes available.
Is is not really something i would like to do. I can write a server that
will serv big files to couple clients in one thread using
select/poll/epoll manually with one thread and one process so i think it
should be possible with libevent too.

> > when client disconnect in the middle of the transfer, however. I can't
> > get fd of the connection form evhttp_request so it's impossible to set
> > event callback for EV_WRITE instead of EV_TIMEOUT.
>
> The problem with how chunked connections work at the moment is that
> you do not get any feedback when they client has closed the
> connection.  I will need to take another look at that and write a test
> case for the scenario.
Yes, exactly. It would be really great if there was a way to register a
callback for sending more data and another one for cleaning when client
is disconnected. That's not something I'm currently able to write
myself, however.

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