[libmill] Re: wait for multiple fds

  • From: Delio Brignoli <brignoli.delio@xxxxxxxxx>
  • To: "libmill@xxxxxxxxxxxxx" <libmill@xxxxxxxxxxxxx>
  • Date: Sun, 26 Jul 2015 21:45:19 +0200

Hi Joseph,

I don't think your reply to my original email was harsh at all. I look forward
to try using libmill in a real world project.

Cheers
--
Delio

On 26/7/2015, at 20:59, Joseph Stewart <joseph.stewart@xxxxxxxxx> wrote:

Delio,

I hope my response wasn't too harsh. I often have philosophical thoughts but
pragmatic actions.

While I can only speak for myself, we're a small group so far and I think
thoughtful questions like yours will only help make libmill better.

I'm looking forward to see what you and others use libmill to create!

VBR,
-joe

On Sun, Jul 26, 2015 at 11:29 AM, Delio Brignoli <brignoli.delio@xxxxxxxxx>
wrote:
Hi Martin,

Thanks for the reply, see comments below.

On 24/7/2015, at 20:12, Martin Sustrik <sustrik@xxxxxxxxxx> wrote:

On 2015-07-24 16:42, Delio Brignoli wrote:

The execution path in serve() depends only on fd and the data read
from it, but what about those cases when what to do next depends on
which subset of fds ‘fired’ and the data read from any number of them?
process_input(fd1, fd2, fd3, …):
while not done:
# do not take this as a proposed API, I am just trying to get
my point across
events = fdmultiplewait(fd1, fd2, fd3)
if events.fd1 == FDW_IN and events.fd2 == FDW_IN and
events.fd2 == FDW_NONE:
#do something or start a coroutine
else:
#do something else or start a different coroutine
In the latter case the set of fds are my ‘channels’ (data from a
remote process or a driver) and I am thinking it would be nice not to
have to ‘wrap’ each into a libmill coroutine in order to use libmill’s
channels to finally choose {} when I could have done the same without
intermediate steps and extra code. For instance, it would be great if
one could use choose {} with fds as well as channels.

The idiomatic way to handle the fd is to read data from the fd until you
have entire message, then push the message to a channel.

Then there's a question of how to wait for messages from all three
different sources. I would do that like this:

m1 = chr(ch1, int);
m2 = chr(ch2, int);
m3 = chr(ch3, int);

The equivalent of my pseudocode above would do something when ch1 and ch2
'returned' something and ch3 did not, and do something different otherwise.
I think 'choose' can do what I want and was just wondering if there was a
better way.

Considering all the answers to my original email I see that limiting to
'wait for a single fd' is deliberate and consider my original question
answered. Thank you all.

--
Delio

Other related posts: