Michael S. Fischer
2007-Nov-20 20:02 UTC
[Eventmachine-talk] Events on I/O other than sockets
Hi Francis, Does EventMachine handle I/O events other than on sockets? I''d love to be able to use it for other forms of async I/O, especially originating from IO.popen style command pipes. I see some hints in the Rdoc that it might be there, but nothing concrete. Best regards, --Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20071120/6562c7f2/attachment.html
From: Michael S. Fischer> > Does EventMachine handle I/O events other than on sockets? > I''d love to be able to use it for other forms of async I/O, > especially originating from IO.popen style command pipes.EM does support IO.popen on Unix. (I believe the Windows implementation is still pending... as there are blocking I/O issues with the stdlib popen on Windows.) Regards, Bill
Michael S. Fischer
2007-Nov-20 20:31 UTC
[Eventmachine-talk] Events on I/O other than sockets
On Nov 20, 2007 8:20 PM, Bill Kelly <billk at cts.com> wrote:> > From: Michael S. Fischer > > > > Does EventMachine handle I/O events other than on sockets? > > I''d love to be able to use it for other forms of async I/O, > > especially originating from IO.popen style command pipes. > > EM does support IO.popen on Unix. (I believe the Windows > implementation is still pending... as there are blocking > I/O issues with the stdlib popen on Windows.)Great! Any example code? --Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20071120/0f09ed0f/attachment.html
Francis Cianfrocca
2007-Nov-21 02:01 UTC
[Eventmachine-talk] Events on I/O other than sockets
On Nov 20, 2007 11:02 PM, Michael S. Fischer <michael at dynamine.net> wrote:> Hi Francis, > > Does EventMachine handle I/O events other than on sockets? I''d love to be > able to use it for other forms of async I/O, especially originating from > IO.popen style command pipes. I see some hints in the Rdoc that it might be > there, but nothing concrete. >As Bill says, we support process descriptors (#popen) and keyboard events on *nix. There was some thought given to console events (in order to support GUI programs), but looking at what happened to Twisted when they tried to do that makes me hesitant to attempt it. The next major feature is user-defined events, which can be used to implement inter-process messaging. What other kinds of events should we support?
On Nov 21, 2007, at 4:01 AM, Francis Cianfrocca wrote:> On Nov 20, 2007 11:02 PM, Michael S. Fischer <michael at dynamine.net> > wrote: >> Hi Francis, >> >> Does EventMachine handle I/O events other than on sockets? I''d >> love to be >> able to use it for other forms of async I/O, especially >> originating from >> IO.popen style command pipes. I see some hints in the Rdoc that >> it might be >> there, but nothing concrete. >> > > > As Bill says, we support process descriptors (#popen) and keyboard > events on *nix. There was some thought given to console events (in > order to support GUI programs), but looking at what happened to > Twisted when they tried to do that makes me hesitant to attempt it. > > The next major feature is user-defined events, which can be used to > implement inter-process messaging. > > What other kinds of events should we support?Is there a facility within EM for receiving events on any file descriptor? This would be useful for a project or two where I am essentially "tailing" a file and processing it whenever it changes.
Francis Cianfrocca
2007-Nov-21 09:44 UTC
[Eventmachine-talk] Events on I/O other than sockets
On Nov 21, 2007 9:21 AM, Chuck Remes <cremes.devlist at mac.com> wrote: >> Is there a facility within EM for receiving events on any file > descriptor? This would be useful for a project or two where I am > essentially "tailing" a file and processing it whenever it changes. >I started writing that and never finished. It just felt like processing disk i/o in an event-driven way would have a small payoff, partly because disk controllers now do so much caching and partly because there''s only so much I/O bandwidth in an Intel-based server in the first place. I could be convinced otherwise.
From: Michael S. Fischer> > On Nov 20, 2007 8:20 PM, Bill Kelly <billk at cts.com> wrote: > > > EM does support IO.popen on Unix. (I believe the Windows > > implementation is still pending... as there are blocking > > I/O issues with the stdlib popen on Windows.) > > Great! Any example code?Here''s an example that popen''s a bunch of `tail -f` processes on a bunch of logfiles. In this example, once we''ve received 10 lines from a given logfile we close the connection. (Note that EventMachine''s popen uses socketpair behind the scenes, so it''s a full-duplex connection between the parent and the child.) require ''eventmachine'' load ''../dorkbuster/server-info.cfg'' class WallflyLogtailHandler < EventMachine::Protocols::LineAndTextProtocol def owner_init(sv_nick) @sv_nick = sv_nick @lines_rcvd = 0 end def receive_line(line) line.chomp! @lines_rcvd += 1 printf("%12s: %s\n", @sv_nick, line) if @lines_rcvd == 10 puts "********** #@sv_nick closing connection **********" close_connection end end end def open_all_logtails $server_list.each do |sv| logpath = "../dorkbuster/sv/#{sv.nick}/wallfly.log" EventMachine::popen("tail -n1 -f #{logpath}", WallflyLogtailHandler) do |handler| handler.owner_init(sv.nick) end end end EventMachine.run { open_all_logtails } Hope this helps, Bill
From: "Chuck Remes" <cremes.devlist at mac.com>> > Is there a facility within EM for receiving events on any file > descriptor? This would be useful for a project or two where I am > essentially "tailing" a file and processing it whenever it changes.I''m doing this with: EventMachine::popen("tail -n1 -f #{logpath}", MyHandler) do ...... Obviously there''s some extra overhead here which may be inappropriate if one is looking for a maximally efficient solution... But it''s working great with me for 50 logfiles or so. Regards, Bill
Michael S. Fischer
2007-Nov-24 00:50 UTC
[Eventmachine-talk] Events on I/O other than sockets
On Nov 21, 2007 2:01 AM, Francis Cianfrocca <garbagecat10 at gmail.com> wrote:> > As Bill says, we support process descriptors (#popen) and keyboard > events on *nix.Would it be possible to get the return value from the process opened? From my reading of the code, it looks like pclose(3) is never called at EOF. It would be great if the exit status could be passed as a parameter to EventMachine::Connection#unbind. --Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20071124/bb6d2f89/attachment.html