The default drb protocol.
Communicates over a TCP socket.
- A
- C
- G
- N
- O
- P
- R
- S
- U
[R] | uri | Get the URI that we are connected to. |
Create a new DRbTCPSocket instance.
uri
is the URI we are connected to.
soc
is the tcp socket we are bound to. config
is
our configuration.
Open a client connection to uri
using configuration
config
.
Open a server listening for connections at uri
using
configuration config
.
# File ../ruby/lib/drb/drb.rb, line 853 def self.open_server(uri, config) uri = 'druby://:0' unless uri host, port, _ = parse_uri(uri) config = {:tcp_original_host => host}.update(config) if host.size == 0 host = getservername soc = open_server_inaddr_any(host, port) else soc = TCPServer.open(host, port) end port = soc.addr[1] if port == 0 config[:tcp_port] = port uri = "druby://#{host}:#{port}" self.new(uri, soc, config) end
# File ../ruby/lib/drb/drb.rb, line 839 def self.open_server_inaddr_any(host, port) infos = Socket::getaddrinfo(host, nil, Socket::AF_UNSPEC, Socket::SOCK_STREAM, 0, Socket::AI_PASSIVE) families = Hash[*infos.collect { |af, *_| af }.uniq.zip([]).flatten] return TCPServer.open('0.0.0.0', port) if families.has_key?('AF_INET') return TCPServer.open('::', port) if families.has_key?('AF_INET6') return TCPServer.open(port) end
Parse uri
into a [uri, option] pair.
On the server side, for an instance returned by open_server, accept a client connection and return a new instance to handle the server's side of this client-server session.
# File ../ruby/lib/drb/drb.rb, line 939 def accept while true s = @socket.accept break if (@acl ? @acl.allow_socket?(s) : true) s.close end if @config[:tcp_original_host].to_s.size == 0 uri = "druby://#{s.addr[3]}:#{@config[:tcp_port]}" else uri = @uri end self.class.new(uri, s, @config) end
Check to see if this connection is alive.
Get the address of our TCP peer (the other end of the socket we are bound to.
On the client side, receive a reply from the server.
On the server side, receive a request from the client.
On the server side, send a reply to the client.
On the client side, send a request to the server.