Parent

Thin::Backends::Base

A Backend connects the server to the client. It handles:

Implementing your own backend

You can create your own minimal backend by inheriting this class and defining the connect and disconnect method. If your backend is not based on EventMachine you also need to redefine the start, stop, stop! and config methods.

Attributes

server[RW]

Server serving the connections throught the backend

timeout[RW]

Maximum time for incoming data to arrive

maximum_connections[RW]

Maximum number of file or socket descriptors that the server may open.

maximum_persistent_connections[RW]

Maximum number of connections that can be persistent

threaded[W]

Allow using threads in the backend.

ssl[W]

Allow using SSL in the backend.

ssl_options[W]

Allow using SSL in the backend.

persistent_connection_count[RW]

Number of persistent connections currently opened

no_epoll[RW]

Disable the use of epoll under Linux

Public Class Methods

new() click to toggle source
    # File lib/thin/backends/base.rb, line 40
40:       def initialize
41:         @connections                    = []
42:         @timeout                        = Server::DEFAULT_TIMEOUT
43:         @persistent_connection_count    = 0
44:         @maximum_connections            = Server::DEFAULT_MAXIMUM_CONNECTIONS
45:         @maximum_persistent_connections = Server::DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS
46:         @no_epoll                       = false
47:       end

Public Instance Methods

close() click to toggle source

Free up resources used by the backend.

    # File lib/thin/backends/base.rb, line 98
98:       def close
99:       end
config() click to toggle source

Configure the backend. This method will be called before droping superuser privileges, so you can do crazy stuff that require godlike powers here.

    # File lib/thin/backends/base.rb, line 87
87:       def config
88:         # See http://rubyeventmachine.com/pub/rdoc/files/EPOLL.html
89:         EventMachine.epoll unless @no_epoll
90:         
91:         # Set the maximum number of socket descriptors that the server may open.
92:         # The process needs to have required privilege to set it higher the 1024 on
93:         # some systems.
94:         @maximum_connections = EventMachine.set_descriptor_table_size(@maximum_connections) unless Thin.win?
95:       end
connection_finished(connection) click to toggle source

Called by a connection when it’s unbinded.

     # File lib/thin/backends/base.rb, line 107
107:       def connection_finished(connection)
108:         @persistent_connection_count -= 1 if connection.can_persist?
109:         @connections.delete(connection)
110:         
111:         # Finalize gracefull stop if there's no more active connection.
112:         stop! if @stopping && @connections.empty?
113:       end
empty?() click to toggle source

Returns true if no active connection.

     # File lib/thin/backends/base.rb, line 116
116:       def empty?
117:         @connections.empty?
118:       end
running?() click to toggle source

Returns true if the backend is connected and running.

     # File lib/thin/backends/base.rb, line 102
102:       def running?
103:         @running
104:       end
size() click to toggle source

Number of active connections.

     # File lib/thin/backends/base.rb, line 121
121:       def size
122:         @connections.size
123:       end
ssl?() click to toggle source
    # File lib/thin/backends/base.rb, line 32
32:       def ssl?; @ssl end
start() click to toggle source

Start the backend and connect it.

    # File lib/thin/backends/base.rb, line 50
50:       def start
51:         @stopping = false
52:         starter   = proc do
53:           connect
54:           @running = true
55:         end
56:         
57:         # Allow for early run up of eventmachine.
58:         if EventMachine.reactor_running?
59:           starter.call
60:         else
61:           EventMachine.run(&starter)
62:         end
63:       end
stop() click to toggle source

Stop of the backend from accepting new connections.

    # File lib/thin/backends/base.rb, line 66
66:       def stop
67:         @running  = false
68:         @stopping = true
69:         
70:         # Do not accept anymore connection
71:         disconnect
72:         stop! if @connections.empty?
73:       end
stop!() click to toggle source

Force stop of the backend NOW, too bad for the current connections.

    # File lib/thin/backends/base.rb, line 76
76:       def stop!
77:         @running  = false
78:         @stopping = false
79:         
80:         EventMachine.stop if EventMachine.reactor_running?
81:         @connections.each { |connection| connection.close_connection }
82:         close
83:       end
threaded?() click to toggle source
    # File lib/thin/backends/base.rb, line 28
28:       def threaded?; @threaded end

Protected Instance Methods

initialize_connection(connection) click to toggle source

Initialize a new connection to a client.

     # File lib/thin/backends/base.rb, line 127
127:         def initialize_connection(connection)
128:           connection.backend                 = self
129:           connection.app                     = @server.app
130:           connection.comm_inactivity_timeout = @timeout
131:           connection.threaded                = @threaded
132:           
133:           if @ssl
134:             connection.start_tls(@ssl_options)
135:           end
136: 
137:           # We control the number of persistent connections by keeping
138:           # a count of the total one allowed yet.
139:           if @persistent_connection_count < @maximum_persistent_connections
140:             connection.can_persist!
141:             @persistent_connection_count += 1
142:           end
143: 
144:           @connections << connection
145:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.