Class: GQTP::Backend::Thread::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Instance Attribute Details

#hostObject

Returns the value of attribute host.



99
100
101
# File 'lib/gqtp/backend/thread.rb', line 99

def host
  @host
end

#portObject

Returns the value of attribute port.



99
100
101
# File 'lib/gqtp/backend/thread.rb', line 99

def port
  @port
end

Instance Method Details

#runObject



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

#shutdownObject



121
122
123
# File 'lib/gqtp/backend/thread.rb', line 121

def shutdown
  @server.shutdown
end