Class: GQTP::Backend::Thread::Server
- Inherits:
-
Object
- Object
- GQTP::Backend::Thread::Server
- Defined in:
- lib/gqtp/backend/thread.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
100 101 102 103 104 105 |
# File 'lib/gqtp/backend/thread.rb', line 100 def initialize(={}) @options = @host = [:host] || "0.0.0.0" @port = [:port] || 10043 @backlog = [:backlog] || 128 end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
99 100 101 |
# File 'lib/gqtp/backend/thread.rb', line 99 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
99 100 101 |
# File 'lib/gqtp/backend/thread.rb', line 99 def port @port end |
Instance Method Details
#run ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/gqtp/backend/thread.rb', line 107 def run @server = TCPServer.new(@host, @port) @server.listen(@backlog) thread = ::Thread.new do loop do client = @server.accept ::Thread.new do yield(IO.new(client)) end end end Request.new(thread) end |
#shutdown ⇒ Object
121 122 123 |
# File 'lib/gqtp/backend/thread.rb', line 121 def shutdown @server.shutdown end |