Class: Metis::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/metis/server.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :host => '0.0.0.0',
  :port => 5668,
  :enable_ssl => true
}

Instance Method Summary collapse

Constructor Details

#initialize(context, options = {}) ⇒ Server

Returns a new instance of Server.



12
13
14
15
16
17
18
19
20
# File 'lib/metis/server.rb', line 12

def initialize(context, options={})
  @context = context
  @options = DEFAULT_OPTIONS.merge(options)

  if @options[:enable_ssl]
    @ssl_context = OpenSSL::SSL::SSLContext.new "SSLv23_server"
    @ssl_context.ciphers = 'ADH'
  end
end

Instance Method Details

#runObject



43
44
45
46
47
48
49
50
51
# File 'lib/metis/server.rb', line 43

def run
  loop do
    client_socket = @server.accept
    Thread.start do
      client = Metis::Client.new(client_socket, @context)
      client.process
    end
  end
end

#startObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/metis/server.rb', line 22

def start
  @server = TCPServer.new(@options[:host], @options[:port])
  @server = OpenSSL::SSL::SSLServer.new(@server, @ssl_context) if @options[:enable_ssl]

  trap(:QUIT) {
    self.stop
    exit(0)
  }

  trap(:TERM) {
    self.stop
    exit(0)
  }

  true
end

#stopObject



39
40
41
# File 'lib/metis/server.rb', line 39

def stop
  @server.stop if @server
end