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

Re: [Libevent-users] filter bufferevents and timeout



Hello,
Ok thank you!
For the moment I just bypassed the flush: because i know when my stream is over i trigger a BEV_EVENT_EOF from the filter callback, and then handle the remaining data in input buffer within the event callback.

I was thinking of a file as a bufferevent output-only:
we read data from a socket into input buffer, filter it then add it to the output buffer which writes into the file.
It could be with a filter bufferevent or a pair of bufferevents for which one could choose to enable input or output only?
Of course one can bypass that by writing into the file from inside the read callback as i'm doing for the time being...

Bruno

----- Mail original -----
De: "Azat Khuzhin" <a3at.mail@xxxxxxxxx>
À: libevent-users@xxxxxxxxxxxxx
Envoyé: Lundi 19 Mars 2018 09:55:52
Objet: Re: [Libevent-users] filter bufferevents and timeout

On Tue, Mar 13, 2018 at 7:42 PM, Bruno CARLUS <b.carlus@xxxxxxxxxxxxx> wrote:
> 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?

Hello,

I don't think so, my guess is that during flush it doesn't call readcb
(in be_filter_flush() there is no bufferevent_trigger_nolock_() like
in be_filter_read_nolock_()).
I will write a test today and will come back to you later, in the evening.

> 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...

How you will poll mmaped fd?
Can you explain this a little bit more? Maybe I'm missing something.

-- 
  Azat.
***********************************************************************
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.