123456789_123456789_123456789_123456789_123456789_

Class: DRb::DRbUNIXSocket

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, DRbTCPSocket
Instance Chain:
self, DRbTCPSocket
Inherits: DRb::DRbTCPSocket
Defined in: lib/drb/unix.rb

Overview

Implements DRb over a UNIX socket

::DRb UNIX socket URIs look like drbunix:<path>?<option>. The option is optional.

Constant Summary

Class Method Summary

DRbTCPSocket - Inherited

.getservername

Returns the hostname of this server.

.new

Create a new DRbTCPSocket instance.

.open

Open a client connection to uri (DRb URI string) using configuration config.

.open_server

Open a server listening for connections at uri using configuration config.

.open_server_inaddr_any

For the families available for host, returns a TCPServer on port.

.uri_option

Parse uri into a [uri, option] pair.

.parse_uri

Instance Attribute Summary

DRbTCPSocket - Inherited

#alive?

Check to see if this connection is alive.

#uri

Get the URI that we are connected to.

Instance Method Summary

DRbTCPSocket - Inherited

#accept

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.

#close

Close the connection.

#peeraddr

Get the address of our TCP peer (the other end of the socket we are bound to.

#recv_reply

On the client side, receive a reply from the server.

#recv_request

On the server side, receive a request from the client.

#send_reply

On the server side, send a reply to the client.

#send_request

On the client side, send a request to the server.

#set_sockopt,
#shutdown

Graceful shutdown.

#stream

Get the socket.

#accept_or_shutdown, #close_shutdown_pipe

Constructor Details

.new(uri, soc, config = {}, server_mode = false) ⇒ DRbUNIXSocket

[ GitHub ]

  
# File 'lib/drb/unix.rb', line 62

def initialize(uri, soc, config={}, server_mode = false)
  super(uri, soc, config)
  set_sockopt(@socket)
  @server_mode = server_mode
  @acl = nil
end

Class Method Details

.open(uri, config)

[ GitHub ]

  
# File 'lib/drb/unix.rb', line 28

def self.open(uri, config)
  filename, = parse_uri(uri)
  soc = UNIXSocket.open(filename)
  self.new(uri, soc, config)
end

.open_server(uri, config)

[ GitHub ]

  
# File 'lib/drb/unix.rb', line 34

def self.open_server(uri, config)
  filename, = parse_uri(uri)
  if filename.size == 0
    soc = temp_server
    filename = soc.path
    uri = 'drbunix:' + soc.path
  else
    soc = UNIXServer.open(filename)
  end
  owner = config[:UNIXFileOwner]
  group = config[:UNIXFileGroup]
  if owner || group
    require 'etc'
    owner = Etc.getpwnam( owner ).uid  if owner
    group = Etc.getgrnam( group ).gid  if group
    File.chown owner, group, filename
  end
  mode = config[:UNIXFileMode]
  File.chmod(mode, filename) if mode

  self.new(uri, soc, config, true)
end

.parse_uri(uri)

[ GitHub ]

  
# File 'lib/drb/unix.rb', line 17

def self.parse_uri(uri)
  if /\Adrbunix:(.*?)(\?(.*))?\z/ =~ uri
    filename = $1
    option = $3
    [filename, option]
  else
    raise(DRbBadScheme, uri) unless uri.start_with?('drbunix:')
    raise(DRbBadURI, 'can\'t parse uri:' + uri)
  end
end

.temp_server (private)

[ GitHub ]

  
# File 'lib/drb/unix.rb', line 72

def self.temp_server
  tmpdir = Dir::tmpdir
  n = 0
  while true
    begin
      tmpname = sprintf('%s/druby%d.%d', tmpdir, $$, n)
      lock = tmpname + '.lock'
      unless File.exist?(tmpname) or File.exist?(lock)
        Dir.mkdir(lock)
        break
      end
    rescue
      raise "cannot generate tempfile '%s'" % tmpname if n >= Max_try
      #sleep(1)
    end
    n += 1
  end
  soc = UNIXServer.new(tmpname)
  Dir.rmdir(lock)
  soc
end

.uri_option(uri, config)

[ GitHub ]

  
# File 'lib/drb/unix.rb', line 57

def self.uri_option(uri, config)
  filename, option = parse_uri(uri)
  return "drbunix:#{filename}", option
end

Instance Method Details

#accept

[ GitHub ]

  
# File 'lib/drb/unix.rb', line 105

def accept
  s = accept_or_shutdown
  return nil unless s
  self.class.new(nil, s, @config)
end

#close

[ GitHub ]

  
# File 'lib/drb/unix.rb', line 95

def close
  return unless @socket
  shutdown # DRbProtocol#shutdown
  path = @socket.path if @server_mode
  @socket.close
  File.unlink(path) if @server_mode
  @socket = nil
  close_shutdown_pipe
end

#set_sockopt(soc)

[ GitHub ]

  
# File 'lib/drb/unix.rb', line 111

def set_sockopt(soc)
  # no-op for now
end