List Info

Thread: Re: EM and popen




Re: EM and popen
user name
2007-04-23 08:25:22
On 4/22/07, Bill Kelly < billkcts.com">billkcts.com&gt; wrote:
 
I guess I'm confused, because what you've written above looks
almost like what I thought I was asking for.   &nbsp;Except I'm
just interested in the pipes, not so much the signals.&nbsp; It
would be fine with me, for example, if EM just by default
converted SIGPIPE and SIGCHLD into CONNECTION_UNBOUND events,
I would think.&nbsp; (EM would handle reaping the zombie for me.)

But let me put fork aside for the moment and just look at the
popen case.

I don't understand why it would require any changes to EM's
core to treat the pipe returned by popen as 'just another
eventable file descriptor'? ; Looking at em.cpp, we already
have the beginnings of event support on nonblocking file
descriptors with _OpenFileForWriting.&nbsp; Why couldn';t the pipe
returned by popen be wrapped in a FileStreamDescriptor in
the same manner?

Rather than requiring changes to EM's core, it seems like it
would fit in quite naturally.  ;Am I missing something?

 
You're probably right. I'm going to try to get to this today. To add a bit to the point about signals: EM should completely hide them (and the parallel mechanism on Windows) from user code. I think with Twisted you get an event (which is triggered by a signal under the covers) that tells you the fork child has ended, which is all you really care about, of course.
Re: EM and popen
country flaguser name
United States
2007-05-29 19:33:24
From: Francis Cianfrocca 
>
> > On 4/22/07, Bill Kelly <billkcts.com> wrote: 
> > 
> > I don't understand why it would require any
changes to EM's
> > core to treat the pipe returned by popen as 'just
another
> > eventable file descriptor'?  Looking at em.cpp, we
already
> > have the beginnings of event support on
nonblocking file 
> > descriptors with _OpenFileForWriting.  Why
couldn't the pipe
> > returned by popen be wrapped in a
FileStreamDescriptor in
> > the same manner?
> > 
> > Rather than requiring changes to EM's core, it
seems like it 
> > would fit in quite naturally.  Am I missing
something?
>
> You're probably right. I'm going to try to get to this
today.
> To add a bit to the point about signals: EM should
completely
> hide them (and the parallel mechanism on Windows) from
user code.
> I think with Twisted you get an event (which is
triggered by a
> signal under the covers) that tells you the fork child
has ended,
> which is all you really care about, of course.

Hi Francis,

Any progress on the eventable popen?

I'm thinking of trying to add this to EM, myself, so I was 
wondering if you may have already made a start on it?

And/or, any thoughts on what the API might look like?  One
of the things I like about popen() in Ruby and Perl, is
that
you can get the PID of the child process.

Looking at Ruby's popen() implementation in io.c, I see
that
they're not using the popen() library call at all; but
instead
are using a custom implementation using fork/exec in order
to obtain the PID (I presume.)

Let's say we added something to the EM 'C' API, like:

  const char *evma_popen (const char *command, const char
*mode);

This would return a binding, and EM would fire the usual
EM_CONNECTION_COMPLETED, _READ, _UNBOUND events.  (Assuming
mode "r" for CONNECTION_READ... If mode were
"w", then presumably
one could use evma_send_data_to_connection() to write to the
pipe.
As far as signals like EPIPE, I figure they should just be
converted to CONNECTION_UNBOUND...?)

And then, in terms of the API, how to ask for the PID?  I
guess,
in keeping with API calls we already have, like
evma_get_peername()
we could add one like:

  int evma_get_pid (const char *binding);
  
...something like that?

Does this seem reasonable?

I'd really like to have an eventable popen(), and I may give

this a shot when I have time.  (BTW, I don't know how to
make
it work on Windows, since their pipes don't work with
select.)


Regards,

Bill



_______________________________________________
Eventmachine-talk mailing list
Eventmachine-talkrubyforge.org
http://rubyforge.org/mailman/listinfo/eventmachine-talk

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )