Class: Rpush::Daemon::Rpc::Server

Inherits:
Object
  • Object
show all
Includes:
Loggable, Reflectable, Singleton
Defined in:
lib/rpush/daemon/rpc/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Reflectable

#reflect

Methods included from Loggable

#log_debug, #log_error, #log_info, #log_warn

Class Method Details

.startObject



12
13
14
# File 'lib/rpush/daemon/rpc/server.rb', line 12

def self.start
  instance.start
end

.stopObject



16
17
18
# File 'lib/rpush/daemon/rpc/server.rb', line 16

def self.stop
  instance.stop
end

Instance Method Details

#startObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rpush/daemon/rpc/server.rb', line 20

def start
  @stop = false

  @thread = Thread.new(UNIXServer.open(Rpc.socket_path)) do |server|
    begin
      loop do
        socket = server.accept
        break if @stop
        read_loop(socket)
      end

      server.close
    rescue StandardError => e
      log_error(e)
    ensure
      File.unlink(Rpc.socket_path) if File.exist?(Rpc.socket_path)
    end
  end
end

#stopObject



40
41
42
43
44
45
46
# File 'lib/rpush/daemon/rpc/server.rb', line 40

def stop
  @stop = true
  UNIXSocket.new(Rpc.socket_path)
  @thread.join if @thread
rescue StandardError => e
  log_error(e)
end