Class: Dizby::BasicConnection
- Defined in:
- lib/dizby/stream/connection.rb
Instance Attribute Summary collapse
-
#shutdown_pipe
readonly
private
Returns the value of attribute shutdown_pipe.
Attributes inherited from Messenger
Instance Method Summary collapse
- #close
-
#initialize(server, stream) ⇒ BasicConnection
constructor
A new instance of BasicConnection.
-
#make_distributed(_obj, _error)
private
when a distributed object is made through a connection, store it so that it doesn't get consumed by the garbage collector.
- #recv_request
- #send_reply(succ, result)
- #wait_for_stream private
Methods inherited from Messenger
Methods included from WritableStream
Methods included from ReadableStream
#check_packet_size, #load_obj, #load_packet, #load_size, #read
Constructor Details
#initialize(server, stream) ⇒ BasicConnection
Returns a new instance of BasicConnection.
13 14 15 16 17 18 19 20 21 |
# File 'lib/dizby/stream/connection.rb', line 13 def initialize(server, stream) super(server, stream) # get the uri that the client recognizes the server as @remote_uri = read @shutdown_pipe = SelfPipe.new(*IO.pipe) @object_space = [] end |
Instance Attribute Details
#shutdown_pipe (readonly, private)
Returns the value of attribute shutdown_pipe.
67 68 69 |
# File 'lib/dizby/stream/connection.rb', line 67 def shutdown_pipe @shutdown_pipe end |
Instance Method Details
#close
44 45 46 47 48 |
# File 'lib/dizby/stream/connection.rb', line 44 def close @object_space.clear shutdown_pipe.close_write if shutdown_pipe super end |
#make_distributed(_obj, _error) (private)
when a distributed object is made through a connection, store it so that it doesn't get consumed by the garbage collector
54 55 56 57 58 |
# File 'lib/dizby/stream/connection.rb', line 54 def make_distributed(_obj, _error) distributed = super @object_space << distributed distributed end |
#recv_request
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dizby/stream/connection.rb', line 23 def recv_request wait_for_stream ref, msg, argc = Array.new(3) { read } @server.log.debug("called through proxy: #{ref} #{msg}") fail ConnectionError, 'too many arguments' if @server.argc_limit < argc argv = Array.new(argc) { read } block = read ro = @server.to_obj(ref) [ro, msg, argv, block] end |
#send_reply(succ, result)
38 39 40 41 42 |
# File 'lib/dizby/stream/connection.rb', line 38 def send_reply(succ, result) write(dump_data(succ) + dump_data(result, !succ)) rescue raise ConnectionError, $!., $!.backtrace end |
#wait_for_stream (private)
60 61 62 63 64 65 |
# File 'lib/dizby/stream/connection.rb', line 60 def wait_for_stream readable, = IO.select([@stream, shutdown_pipe.read]) fail RemoteServerShutdown if readable.include?(shutdown_pipe.read) rescue IOError raise RemoteServerShutdown end |