Class: DRb::DRbUNIXSocket
- Inherits:
-
DRbTCPSocket
- Object
- DRbTCPSocket
- DRb::DRbUNIXSocket
- Defined in:
- lib/emdrb/unix.rb
Overview
Unix domain socket transport
Instance Method Summary collapse
- #client_connect(prot) ⇒ Object
-
#initialize(uri, config = {}) ⇒ DRbUNIXSocket
constructor
A new instance of DRbUNIXSocket.
- #start_server(prot) ⇒ Object
- #stop_server ⇒ Object
Constructor Details
#initialize(uri, config = {}) ⇒ DRbUNIXSocket
Returns a new instance of DRbUNIXSocket.
31 32 33 34 35 36 37 38 |
# File 'lib/emdrb/unix.rb', line 31 def initialize(uri, config={}) @uri = (uri.nil?) ? 'drbunix:' : uri @filename, @option = self.class.parse_uri(@uri) @filename.untaint @port.untaint @config = config @acl = nil end |
Instance Method Details
#client_connect(prot) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/emdrb/unix.rb', line 78 def client_connect(prot) EventMachine.connect_unix_domain(@filename, prot) do |c| if block_given? yield c end end end |
#start_server(prot) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/emdrb/unix.rb', line 40 def start_server(prot) if @conndesc return(@conndesc) end lock = nil if @filename.nil? 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) @filename = tmpname break end rescue raise "cannot generate tempfile `%s'" % tmpname if n >= Max_try #sleep(1) end n += 1 end end @conndesc = EventMachine::start_unix_domain_server(@filename, prot) do |conn| if block_given? yield conn end end if lock Dir.rmdir(lock) end end |
#stop_server ⇒ Object
86 87 88 89 |
# File 'lib/emdrb/unix.rb', line 86 def stop_server super File.unlink(@filename) end |