Class: OTerm::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(executor, port = 6060, debug = false) ⇒ Server

Returns a new instance of Server.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/oterm/server.rb', line 13

def initialize(executor, port=6060, debug=false)
  @debug = debug
  @stop = false
  @listeners = []
  @acceptThread = Thread.start() do
    server = TCPServer.new(port)
    while !stop do
      Thread.start(server.accept()) do |con|
        @listeners << Listener.new(self, con, executor)
      end
    end
  end
end

Instance Attribute Details

#acceptThreadObject

Returns the value of attribute acceptThread.



8
9
10
# File 'lib/oterm/server.rb', line 8

def acceptThread
  @acceptThread
end

#debugObject

Returns the value of attribute debug.



11
12
13
# File 'lib/oterm/server.rb', line 11

def debug
  @debug
end

#listenersObject

Returns the value of attribute listeners.



10
11
12
# File 'lib/oterm/server.rb', line 10

def listeners
  @listeners
end

#stopObject

Returns the value of attribute stop.



9
10
11
# File 'lib/oterm/server.rb', line 9

def stop
  @stop
end

Instance Method Details

#joinObject



35
36
37
# File 'lib/oterm/server.rb', line 35

def join()
  @acceptThread.join()
end

#remove_listener(listener) ⇒ Object



31
32
33
# File 'lib/oterm/server.rb', line 31

def remove_listener(listener)
  @listeners.delete(listener)
end

#shutdownObject



27
28
29
# File 'lib/oterm/server.rb', line 27

def shutdown()
  @acceptThread.exit()
end