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

Re: [Libevent-users] Design struggle





On Thu, Sep 4, 2014 at 11:43 AM, Azat Khuzhin <a3at.mail@xxxxxxxxx> wrote:
Nope, evbuffers can't work with UDP.

â:o\
I hope support for it would come eventually, that could help buffering the received data automatically.â
âI do not know if that would change much of my code though. I would still need to dispatch the main buffer to all the handlers' one.â

Right (at least for TCP).

âThanks for the support. That's relieving to know I am not messing things up (at least not too much ^^).â
Â

Yep, now I understand, just like I said above.

âYup exactly... but you also asked why not binding all the handlers directly to the socket fd. ;o)â
Â

Here is a sample case:
> received "message1"
> triggers READ event on handler1 -> handler1 reads "message1" and processes
> it
> triggers READ event on handler2 -> handler2 reads "message2" and processes
> it

s/message2/message1/ I guess.

âYup indeed.â
You got the point anyway.


>
> received "message2"
> triggers READ event on handler1 (still busy processing)
> triggers READ event on handler2 -> handler2 reads "message2" and processes
> it
>
> received "message3"
> triggers READ event on handler1 -> handler1 reads "message3" and processes
> it
> triggers READ event on handler2 -> handler2 reads "message3" and processes
> it
>
> Whoops! handler1 missed "message2"...

Why it will missed "message2", if you filled handler1.buffer with
"message2" and then "message3", it must handle firstly "message2" and
only after this "message3".
Am I missing something?

âOh yeah, you're right...

I am still mixing up asynchronicity with parallel processing...
I thought that while handler1 was processing, data could be appended to its buffer, but if the handler had already finished reading its buffer, and at the end decided to reset it, it would discard data...

But in my case there is single process/thread, so data cannot be appended *while* handler1 is running...
Really I need to stick that mono-processing in my head, I have created loads of false-problems since I started my project... ^^
I *do not* need to check if any handler is running when reading network... 'cause it cannot... -_-'. What a loss of time!

Yeah thanks the buffer is indeed totally ordered still...

Anyhow, that does not change the fact that I need a single handler for the network reading, and then dispatch the messages to handler, filling their individual buffer and manually activating their event to trigger them, does it?
---
B. R.
â