5 raise(LoadError, "UNIXServer is required") unless defined?(UNIXServer)
9 class DRbUNIXSocket < DRbTCPSocket
10 def self.parse_uri(uri)
11 if /^drbunix:(.*?)(\?(.*))?$/ =~ uri
16 raise(DRbBadScheme, uri) unless uri =~ /^drbunix:/
17 raise(DRbBadURI, 'can\'t parse uri:' + uri)
21 def self.open(uri, config)
22 filename, option = parse_uri(uri)
24 soc = UNIXSocket.open(filename)
25 self.new(uri, soc, config)
28 def self.open_server(uri, config)
29 filename, option = parse_uri(uri)
33 uri = 'drbunix:' + soc.path
35 soc = UNIXServer.open(filename)
37 owner = config[:UNIXFileOwner]
38 group = config[:UNIXFileGroup]
41 owner = Etc.getpwnam( owner ).uid if owner
42 group = Etc.getgrnam( group ).gid if group
43 File.chown owner, group, filename
45 mode = config[:UNIXFileMode]
46 File.chmod(mode, filename) if mode
48 self.new(uri, soc, config, true)
51 def self.uri_option(uri, config)
52 filename, option = parse_uri(uri)
53 return "drbunix:#{filename}", option
56 def initialize(uri, soc, config={}, server_mode = false)
57 super(uri, soc, config)
59 @server_mode = server_mode
63 # import from tempfile.rb
71 tmpname = sprintf('%s/druby%d.%d', tmpdir, $$, n)
72 lock = tmpname + '.lock'
73 unless File.exist?(tmpname) or File.exist?(lock)
78 raise "cannot generate tempfile `%s'" % tmpname if n >= Max_try
83 soc = UNIXServer.new(tmpname)
91 path = @socket.path if @server_mode
93 File.unlink(path) if @server_mode
99 self.class.new(nil, s, @config)
103 soc.fcntl(Fcntl::F_SETFL, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
107 DRbProtocol.add_protocol(DRbUNIXSocket)