Class: GQTP::Server
- Inherits:
-
Object
- Object
- GQTP::Server
- Defined in:
- lib/gqtp/server.rb
Defined Under Namespace
Classes: Request
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.
- #on_connect(*arguments, &block) ⇒ Object
- #on_request(*arguments, &block) ⇒ Object
- #run ⇒ Object
- #shutdown ⇒ Object
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 = .dup @options[:host] ||= @options[:address] || "0.0.0.0" @options[:port] ||= 10043 @on_request = nil @on_connect = nil end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
23 24 25 |
# File 'lib/gqtp/server.rb', line 23 def host @host end |
#port ⇒ Object
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 |
#run ⇒ Object
32 33 34 35 36 37 |
# File 'lib/gqtp/server.rb', line 32 def run @backend = create_backend @backend.run do |client| process_request(client, on_connect(client)) end end |
#shutdown ⇒ Object
39 40 41 |
# File 'lib/gqtp/server.rb', line 39 def shutdown @backend.shutdown end |