Class: Vuf::Server

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

Instance Method Summary collapse

Constructor Details

#initialize(port, session_klass) ⇒ Server

Returns a new instance of Server.



4
5
6
7
8
9
10
11
12
# File 'lib/vuf/server.rb', line 4

def initialize(port, session_klass)
  @port = port
  @sessions_ctx = {}
  @server_thread = nil
  @closing_q = Queue.new
  @session_klass = session_klass
  @wp = Vuf::WorkingPool.new(4)
  @wp.run
end

Instance Method Details

#shutdownObject



38
39
40
41
42
# File 'lib/vuf/server.rb', line 38

def shutdown
  @running = false
  @server_thread.join unless @server_thread.nil?
  @server_thread = nil
end

#startObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vuf/server.rb', line 14

def start
  if @server_thread.nil?
    @running = true
    @server_thread = Thread.new do
      Logger.debug "Server Starting"
      begin
        @server = TCPServer.new @port
        @s_list = [@server]
        while @running
          close_ended_sessions
          rsl, = IO.select(@s_list,[],[],1)
          next if rsl.nil? # Timeout
          accept(rsl) # Handle acceptance of new incoming session
          rsl.each { |s| serve s }
        end
      rescue => e
        Logger.error "Server Error [#{e}]
          #{e.message}
          #{e.backtrace.join("\n")}"
      end
    end
  end
end