Class: DRb::DRbUNIXSocket

Inherits:
DRbTCPSocket show all
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 collapse

Max_try =

import from tempfile.rb

10

Instance Attribute Summary

Attributes inherited from DRbTCPSocket

#uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DRbTCPSocket

#alive?, getservername, open_server_inaddr_any, #peeraddr, #recv_reply, #recv_request, #send_reply, #send_request, #shutdown, #stream

Constructor Details

#initialize(uri, soc, config = {}, server_mode = false) ⇒ DRbUNIXSocket

Returns a new instance of DRbUNIXSocket.



63
64
65
66
67
68
# File 'lib/drb/unix.rb', line 63

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) ⇒ Object



28
29
30
31
32
33
# File 'lib/drb/unix.rb', line 28

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

.open_server(uri, config) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/drb/unix.rb', line 35

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) ⇒ Object

:stopdoc:



17
18
19
20
21
22
23
24
25
26
# File 'lib/drb/unix.rb', line 17

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) ⇒ Object



58
59
60
61
# File 'lib/drb/unix.rb', line 58

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

Instance Method Details

#acceptObject



105
106
107
108
109
# File 'lib/drb/unix.rb', line 105

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

#closeObject



96
97
98
99
100
101
102
103
# File 'lib/drb/unix.rb', line 96

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

#set_sockopt(soc) ⇒ Object



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

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