Class: GQTP::Connection::Thread::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/gqtp/connection/thread.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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={})
  @options = options
  @address = options[:address] || "0.0.0.0"
  @port = options[:port] || 10041
  @backlog = options[:backlog] || 128
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



95
96
97
# File 'lib/gqtp/connection/thread.rb', line 95

def address
  @address
end

#portObject

Returns the value of attribute port.



95
96
97
# File 'lib/gqtp/connection/thread.rb', line 95

def port
  @port
end

Instance Method Details

#runObject



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

#shutdownObject



117
118
119
# File 'lib/gqtp/connection/thread.rb', line 117

def shutdown
  @server.shutdown
end