Class: DRb::DRbUNIXSocket
- Inherits:
-
DRbTCPSocket
- Object
- DRbTCPSocket
- DRb::DRbUNIXSocket
- 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
Class Method Summary collapse
- .open(uri, config) ⇒ Object
- .open_server(uri, config) ⇒ Object
-
.parse_uri(uri) ⇒ Object
:stopdoc:.
- .uri_option(uri, config) ⇒ Object
Instance Method Summary collapse
- #accept ⇒ Object
- #close ⇒ Object
-
#initialize(uri, soc, config = {}, server_mode = false) ⇒ DRbUNIXSocket
constructor
A new instance of DRbUNIXSocket.
- #set_sockopt(soc) ⇒ Object
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.
62 63 64 65 66 67 |
# 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) ⇒ Object
28 29 30 31 32 |
# 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) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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) ⇒ 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 /\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 |
.uri_option(uri, config) ⇒ Object
57 58 59 60 |
# 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 ⇒ Object
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 |
#close ⇒ Object
95 96 97 98 99 100 101 102 103 |
# 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) ⇒ Object
111 112 113 |
# File 'lib/drb/unix.rb', line 111 def set_sockopt(soc) # no-op for now end |