Class: GQTP::Server

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

Defined Under Namespace

Classes: Request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



24
25
26
27
28
29
30
# File 'lib/gqtp/server.rb', line 24

def initialize(options={})
  @options = options.dup
  @options[:address] ||= "0.0.0.0"
  @options[:port] ||= 10041
  @on_request = nil
  @on_connect = nil
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



23
24
25
# File 'lib/gqtp/server.rb', line 23

def address
  @address
end

#portObject

Returns the value of attribute port.



23
24
25
# File 'lib/gqtp/server.rb', line 23

def port
  @port
end

Instance Method Details

#on_connect(*arguments, &block) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gqtp/server.rb', line 43

def on_connect(*arguments, &block)
  if block_given?
    @on_connect = block
  else
    client, = arguments
    if @on_connect
      @on_connect.call(client)
    else
      nil
    end
  end
end

#on_request(*arguments, &block) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/gqtp/server.rb', line 56

def on_request(*arguments, &block)
  if block_given?
    @on_request = block
  else
    request, client, connect_info = arguments
    @on_request.call(request, client, connect_info)
  end
end

#runObject



32
33
34
35
36
37
# File 'lib/gqtp/server.rb', line 32

def run
  @connection = create_connection
  @connection.run do |client|
    process_request(client, on_connect(client))
  end
end

#shutdownObject



39
40
41
# File 'lib/gqtp/server.rb', line 39

def shutdown
  @connection.shutdown
end