Created
May 18, 2011 14:22
-
-
Save rparker/978662 to your computer and use it in GitHub Desktop.
Remote App that does socket.write(cmd) does not get socket.recvfrom(16) 'til after printing completes!
This file contains hidden or 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 Feeder < EventMachine::Connection | |
def initialize(q) | |
@q = q | |
end | |
# Only the first and last lines will stay after this is debugged | |
# How can the send_data() or the remote's recvfrom() not complete | |
# until after the channel.push() subscriber gets done, 30 minutes from now? | |
def receive_data(cmd) | |
send_data cmd + '.'@(16 - cmd.size) # ack to the web app, padded to fill recvfrom(16) | |
close_connection_after_writing # make sure the web app's read() can't hang | |
sleep 10 # no good reason | |
@q.push cmd | |
end | |
end | |
... | |
EventMachine::run { | |
q = EM::Channel.new | |
EM::start_server '127.0.0.1', 8814, Feeder, q | |
printer = q.subscribe{|msg| printer1.print(msg)} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment