Class: SpiderGazelle::Spider::Binding

Inherits:
Object
  • Object
show all
Defined in:
lib/spider-gazelle/spider/binding.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(iterator, options) ⇒ Binding

Returns a new instance of Binding.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/spider-gazelle/spider/binding.rb', line 11

def initialize(iterator, options)
    @options = options

    @logger = Logger.instance
    @signaller = Signaller.instance
    @thread = @signaller.thread
    @iterator = iterator

    @port = @options[:port]
    @app, @app_port, @tls = AppStore.lookup(options[:rackup])

    @http1_cache = []
    @http2_cache = []
    @return_http1 = proc { |parser| @http1_cache << parser }
    @return_http2 = proc { |parser| @http2_cache << parser }
    @parser_count = 0
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



8
9
10
# File 'lib/spider-gazelle/spider/binding.rb', line 8

def app
  @app
end

#app_portObject (readonly)

Returns the value of attribute app_port.



8
9
10
# File 'lib/spider-gazelle/spider/binding.rb', line 8

def app_port
  @app_port
end

#tcpObject (readonly)

Returns the value of attribute tcp.



8
9
10
# File 'lib/spider-gazelle/spider/binding.rb', line 8

def tcp
  @tcp
end

#tlsObject (readonly)

Returns the value of attribute tls.



8
9
10
# File 'lib/spider-gazelle/spider/binding.rb', line 8

def tls
  @tls
end

Instance Method Details

#bindObject

Bind the application to the selected port



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/spider-gazelle/spider/binding.rb', line 30

def bind
    # Bind the socket
    @tcp = @thread.tcp
    @tcp.enable_simultaneous_accepts
    
    if @tls
        @tcp.bind @options[:host], @port do |client|
            prepare_client_tls client
        end
    else
        @tcp.bind @options[:host], @port do |client|
            prepare_client client
        end
    end
    @tcp.listen 10000

    @logger.info "Listening on tcp://#{@options[:host]}:#{@port}"

    @tcp.catch do |error|
        begin
            @logger.print_error(error)
        rescue
        ensure
            @signaller.general_failure
        end
    end
    @tcp
end

#unbindObject

Close the bindings



60
61
62
63
# File 'lib/spider-gazelle/spider/binding.rb', line 60

def unbind
    @tcp.close unless @tcp.nil?
    @tcp
end