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.


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

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)


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

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


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

def accept
  socket = super

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

#close


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

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

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

  close_shutdown_pipe
end