Created
August 12, 2011 12:13
-
-
Save vpereira/1141924 to your computer and use it in GitHub Desktop.
Eventmachine based named pipe reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fcntl' | |
require 'eventmachine' | |
#what is needed | |
#mkfifo mypipe | |
#that everything written thru the pipe have a "\n" | |
#ex: echo "foobar\n" > mypipe | |
#HPO = Handle Pipe Output | |
module HPO | |
def notify_readable | |
puts @io.readlines | |
end | |
def unbind | |
EM.next_tick do | |
data = @io.read | |
puts dat | |
end | |
end | |
end | |
EM.run { | |
fd = IO.sysopen('mypipe',Fcntl::O_RDONLY|Fcntl::O_NONBLOCK) | |
#i think i dont have to repeat the open mode but egal | |
myIO = IO.new(fd,Fcntl::O_RDONLY|Fcntl::O_NONBLOCK) | |
fdmon = EM.watch myIO, HPO | |
fdmon.notify_readable = true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment