On Fri, Aug 29, 2014 at 05:53:50PM +0200, B.R. wrote:I guess only one of this: protocol || port
> 1Â) Filters are created cointaining information of connections they should
> be bound to (protocol, port), events that should trigger them and a
> I) If multiple filters ask to be triggered on READ event on the sameIt depends from how you use this.
> socket, what will they see? Will they all be able to read the same message
> which triggered the event and not another one (ie another message received
> while processing the filter list)?
Kernel will just return array of bytes when you call read() on some
fd/socket, and once you read it, the second read() will never return the
same portion of data.
You could use evbuffer, to save data, and then feed it to every filter
that assigned to this fd/socket, and drain it when you finished.
>This is not safe, because write(2) not always will write all you portion
> II) If multiple filters wanna write data to the socket, is it safe to have
> each filter having its separate buffer and triggering its own WRITE event
> on it?
ââ
of data, it could write less then @count, and return this value to
libevent, and then event loop will schedule the second WRITE event for
the same fd/socket:
write(10, foobar[4096]foobaz[4096], 8192) = 4096 # event1
write(10, barfoo[4096]bazfoo[4096], 8192) = 4096 # event2
write(10, foobaz[4096], 4096) = 4096 # event1
write(10, bazfoo[4096], 4096) = 4096 # event2
...
read(10, buf, 8192*2) = 8192*2
Actual:
buf = foobar[4096]barfoo[4096]foobaz[4096]bazfoo[4096]
Expected:
buf = foobar[4096]foobaz[4096]barfoo[4096]bazfoo[4096]
>Why you want to do it manually?
> Here is a use case summing up both previous inquiries:
> Say a filter wrote data to a socket after parsing the content it read on
> it, and that the peer reacted to that answer, what will subsequent filters,
> for which the READ event has been triggered by the initial message, read?
> a) Initial message?
> b) Either initial message or answer (race, undecided)?
> c) Nothing since the event has been canceled (not pending anymore), the
> subsequent filters will only receive a new event for READ on reception of
> the answer
>
> I am thinking of using a dispatcher which would sequentially (and manually)
> trigger the event of each of the filters. However that implies not linking
> the filters event with the socket, thus forcing me to maintain a separateWhich problem?
> buffer for each of the filter (with memory and processing overhead that
> implies). Moreover, the problem reappears if another message is received on
> the socket while the dispatching loop is at work... and the sequential work
> makes the benefit of the event-based system disappear!
You mean that you filter-handling stuff works significantly slower than
read/write?
>
> I do not know if the bufferevents would be useful to my case. Anyway, those
> are not an option, since part of the traffic I am handling is UDP datagrams.