In Files

  • drb/unix.rb

DRb::DRbUNIXSocket

Constants

Max_try

import from tempfile.rb

Public Class Methods

new(uri, soc, config={}, server_mode = false) click to toggle source
 
               # File drb/unix.rb, line 56
def initialize(uri, soc, config={}, server_mode = false)
  super(uri, soc, config)
  set_sockopt(@socket)
  @server_mode = server_mode
  @acl = nil
end
            
open(uri, config) click to toggle source
 
               # File drb/unix.rb, line 21
def self.open(uri, config)
  filename, option = parse_uri(uri)
  filename.untaint
  soc = UNIXSocket.open(filename)
  self.new(uri, soc, config)
end
            
open_server(uri, config) click to toggle source
 
               # File drb/unix.rb, line 28
def self.open_server(uri, config)
  filename, option = 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) click to toggle source
 
               # File drb/unix.rb, line 10
def self.parse_uri(uri)
  if /^drbunix:(.*?)(\?(.*))?$/ =~ uri
    filename = $1
    option = $3
    [filename, option]
  else
    raise(DRbBadScheme, uri) unless uri =~ /^drbunix:/
    raise(DRbBadURI, 'can\t parse uri:' + uri)
  end
end
            
uri_option(uri, config) click to toggle source
 
               # File drb/unix.rb, line 51
def self.uri_option(uri, config)
  filename, option = parse_uri(uri)
  return "drbunix:#{filename}", option
end
            

Public Instance Methods

accept() click to toggle source
 
               # File drb/unix.rb, line 97
def accept
  s = @socket.accept
  self.class.new(nil, s, @config)
end
            
close() click to toggle source
 
               # File drb/unix.rb, line 89
def close
  return unless @socket
  path = @socket.path if @server_mode
  @socket.close
  File.unlink(path) if @server_mode
  @socket = nil
end
            
set_sockopt(soc) click to toggle source
 
               # File drb/unix.rb, line 102
def set_sockopt(soc)
  soc.fcntl(Fcntl::F_SETFL, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
end