Created
October 27, 2017 23:00
-
-
Save anonymous/2ab856e1a206b1fbf8594217563b6a39 to your computer and use it in GitHub Desktop.
Example nonblocking read from a Named Pipe (created elsewhere)
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
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