Skip to content

Instantly share code, notes, and snippets.

Created October 27, 2017 23:00
Show Gist options
  • Save anonymous/2ab856e1a206b1fbf8594217563b6a39 to your computer and use it in GitHub Desktop.
Save anonymous/2ab856e1a206b1fbf8594217563b6a39 to your computer and use it in GitHub Desktop.
Example nonblocking read from a Named Pipe (created elsewhere)
class Engine
def initialize #pipe_ui_wr, pipe_eng_rdr
#...
# call named_pipe method which returns opened pipe
@pipe_from_ui = named_pipe( Pipes[:engine_in], "r" )
msg_ui = @pipe_from_ui.gets # blocks until ui msg
#...
end
def main_loop argh
# ...
while _exec_state_int == 1
# handle UI-messages
msg_ui = nil
begin
msg_ui = @pipe_from_ui.read_nonblock(2)
rescue IO::WaitReadable
IO.select([@pipe_from_ui], [], [], 0)
#next
end
if msg_ui != nil
msg_ui = msg_ui.strip
p " ***** Engine got ui message: #{msg_ui}"
# etc etc
end
# do other while stuff
end
#...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment