Class: GQTP::Connection::Thread::Server
- Inherits:
-
Object
- Object
- GQTP::Connection::Thread::Server
- Defined in:
- lib/gqtp/connection/thread.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#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.
96 97 98 99 100 101 |
# File 'lib/gqtp/connection/thread.rb', line 96 def initialize(={}) @options = @address = [:address] || "0.0.0.0" @port = [:port] || 10041 @backlog = [:backlog] || 128 end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
95 96 97 |
# File 'lib/gqtp/connection/thread.rb', line 95 def address @address end |
#port ⇒ Object
Returns the value of attribute port.
95 96 97 |
# File 'lib/gqtp/connection/thread.rb', line 95 def port @port end |
Instance Method Details
#run ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/gqtp/connection/thread.rb', line 103 def run @server = TCPServer.new(@address, @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
117 118 119 |
# File 'lib/gqtp/connection/thread.rb', line 117 def shutdown @server.shutdown end |