Skip to content

Instantly share code, notes, and snippets.

@vpereira
Created August 12, 2011 12:13
Show Gist options
  • Save vpereira/1141924 to your computer and use it in GitHub Desktop.
Save vpereira/1141924 to your computer and use it in GitHub Desktop.
Eventmachine based named pipe reader
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