Class: Dizby::UnixProtocol::Server

Inherits:
BasicServer show all
Includes:
PolymorphicDelegated
Defined in:
lib/dizby/protocols/unix.rb

Instance Attribute Summary

Attributes inherited from BasicServer

#exported_uri, #front, #shutdown_pipe, #stream, #uri

Attributes inherited from AbstractServer

#log

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PolymorphicDelegated

included

Methods inherited from BasicServer

#add_uri_alias, #alive?, #close_shutdown_pipe, #here?, #shutdown, #to_id, #to_obj

Methods included from ClassicAttributeAccess

#attr_accessor, #attr_reader, #attr_writer

Methods inherited from AbstractServer

#alive?, #connect_to, #make_distributed, #shutdown, #spawn_on

Methods included from Configurable

#config_accessor, #config_reader, #config_writer

Constructor Details

#initialize(front, config, filename) ⇒ Server

Returns a new instance of Server.


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dizby/protocols/unix.rb', line 43

def initialize(front, config, filename)
  unless filename
    temp = Tempfile.new(%w( dizby-unix .socket ))
    filename = temp.path
    temp.close!
  end

  socket = UNIXServer.open(filename)
  UnixProtocol.apply_sockopt(socket)

  super("drbunix:#{filename}", front, socket, config)

  self.class.set_permissions(filename, config)
end

Class Method Details

.set_permissions(filename, config) (private)


78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/dizby/protocols/unix.rb', line 78

def self.set_permissions(filename, config)
  owner = config[:unix_owner]
  group = config[:unix_group]
  mode = config[:unix_mode]

  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

  File.chmod(mode, filename) if mode
end

Instance Method Details

#accept


71
72
73
74
75
76
# File 'lib/dizby/protocols/unix.rb', line 71

def accept
  socket = super

  UnixProtocol.apply_sockopt(socket)
  BasicConnection.new(self, socket)
end

#close


58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/dizby/protocols/unix.rb', line 58

def close
  if stream
    path = stream.path
    stream.close
    self.stream = nil

    log.debug("unlinking #{path}")
    File.unlink(path)
  end

  close_shutdown_pipe
end