public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
macournoyer (author)
Tue Feb 05 20:26:06 -0800 2008
commit  d768ff30186e03a0e4167c48cc9d3c6ba55514d8
tree    137cd68fee7c5757fe28193bbca44d2ae61e451a
parent  6283c1164dffe934e4d84803a1b8201a00e679dd
thin / lib / thin / connectors / connector.rb
100644 61 lines (50 sloc) 1.631 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
58
59
60
61
module Thin
  module Connectors
    # A Connector connect the server to the client. It handles:
    # * connection/disconnection to the server
    # * initialization of the connections
    # * manitoring of the active connections.
    class Connector
      include Logging
      
      # Server serving the connections throught the connector
      attr_reader :server
      
      # Maximum time for incoming data to arrive
      attr_accessor :timeout
      
      def initialize
        @connections = []
        @timeout = 60 # sec
      end
            
      # Free up resources used by the connector.
      def close
      end
      
      def server=(server)
        @server = server
        @silent = @server.silent
      end
            
      # Initialize a new connection to a client.
      def initialize_connection(connection)
        connection.connector = self
        connection.app = @server.app
        connection.comm_inactivity_timeout = @timeout
        connection.silent = @silent
 
        @connections << connection
      end
      
      # Close all active connections.
      def close_connections
        @connections.each { |connection| connection.close_connection }
      end
      
      # Called by a connection when it's unbinded.
      def connection_finished(connection)
        @connections.delete(connection)
      end
      
      # Returns +true+ if no active connection.
      def empty?
        @connections.empty?
      end
      
      # Number of active connections.
      def size
        @connections.size
      end
    end
  end
end