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

Re: [Libevent-users] filter bufferevents and timeout



Hello,

I just identified a little problem in my code:
I use a filter bufferevent wrapped on a socket bufferevent, for example:

bev = bufferevent_socket_new(base, listener, BEV_OPT_CLOSE_ON_FREE);
struct timeval timeout_read = {5, 0};
bufferevent_set_timeouts(bev, &timeout_read, NULL);
bufferevent_setwatermark(bev, EV_READ, 1500, 0);

bev_filter = bufferevent_filter_new(bev, readandfiltercb, NULL, BEV_OPT_CLOSE_ON_FREE, NULL, NULL);
bufferevent_setwatermark(bev_filter, EV_READ, 3000, 0);
bufferevent_setcb(bev_filter, freadcb, fwritecb, eventcb, NULL);

I'm sending 1000 bytes packets on this socket.
readandfiltercb is called every 2 packets: it filters data and copy it to the bev_filter input buffer.
freadcb is then called ok.

But when udp stream is over, it remains one 1000 bytes packet in the buffer.
eventcb is called because of the timeout: then it flushes bufferevent
readandfiltercb is called ok: it filters and copies last bytes to bev_filter input buffer.
But then freadcb is not called at all.

Is it normal?
How to force bypass the watermark and flush bev_filter input buffer as well?


Last point: Is the underlying fd of a bufferevent can be a mmap file?
I could not find reference to the use of EVBUFFER_SENDFILE in the doc...

Thank you!

----- Mail original -----
De: "Azat Khuzhin" <a3at.mail@xxxxxxxxx>
À: libevent-users@xxxxxxxxxxxxx
Envoyé: Jeudi 16 Novembre 2017 11:25:18
Objet: Re: [Libevent-users] filter bufferevents and timeout

On Wed, Nov 15, 2017 at 6:32 PM, Bruno CARLUS <b.carlus@xxxxxxxxxxxxx> wrote:
> Hi,
>
> I have few questions as I go further in my project:
>
> - regarding bufferevent_filter: I need to retrieve udp data on a socket, filter it according to my protocol and write received data to a file. I was thinking on a read cb tranfering data (evbuffer_add_buffer or evbuffer_add_buffer_reference) from the input buffer of my bufferevent_filter to the output_buffer of another bufferevent linked to my file (mmaped). Is it the right method? How to minimize memory allocation in these operations for a high throughput?

evbuffer_add_buffer() will *moves* data from one buffer to another,
and I guess that this is pretty much what you need, while
evbuffer_add_buffer_reference() will leave a copy which you don't need
anyway (and it will use EVBUFFER_MULTICAST which will *share* the
chain between two buffers).

If you hadn't been needed filtering, you would have been able to use
EVBUFFER_SENDFILE (via evbuffer directly)

> - i read that bufferevent does not support udp yet but it seems to work in my tests (i receive data only, never send) ... What are exacly the limitations ?

Well most of the code assume that it works with stream oriented data,
for more info look at:
  http://archives.seul.org/libevent/users/Dec-2010/msg00008.html
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.