Accepts inbound connections from other peers using TCP. After the peer finishes sending data, the connection is terminated. No data is returned to the sender.
# File lib/journeta/peer_listener.rb, line 14 14: def go 15: begin 16: # Grab configuration information from the injected object. 17: port = @engine.peer_port 18: socket = TCPServer.new(port) 19: putsd "Listening on port #{port}" 20: 21: begin 22: loop do 23: 24: session = socket.accept 25: # We'll put the actual handling of the new session in the background so we 26: # can continue listening for new connections as soon as possible. 27: Thread.new(session) do |session| 28: data = '' 29: # Read every last bit from the socket before passing off to the handler. 30: while more = session.gets 31: data += more 32: end 33: begin 34: msg = YAML::load(data) 35: h = @engine.peer_handler 36: h.call msg 37: rescue 38: putsd "YAML could not be deserialized! The data will not be passed up to the application." 39: end 40: end 41: end 42: rescue 43: putsd "Session closed." 44: end 45: ensure 46: putsd "Closing peer listener socket." 47: # session.close 48: # socket.close 49: end 50: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.