Class: Metis::Server
- Inherits:
-
Object
- Object
- Metis::Server
- 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
-
#initialize(context, options = {}) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
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, ={}) @context = context @options = DEFAULT_OPTIONS.merge() if @options[:enable_ssl] @ssl_context = OpenSSL::SSL::SSLContext.new "SSLv23_server" @ssl_context.ciphers = 'ADH' end end |
Instance Method Details
#run ⇒ Object
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 |
#start ⇒ Object
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 |
#stop ⇒ Object
39 40 41 |
# File 'lib/metis/server.rb', line 39 def stop @server.stop if @server end |