Sha256: 4f86a08b8700eef519e0ba9be1e5c999d7c880999c14077aeee6d81a138e800d

Contents?: true

Size: 1.44 KB

Versions: 24

Compression:

Stored size: 1.44 KB

Contents

module Thin
  module Backends
    # Backend to act as a UNIX domain socket server.
    class UnixServer < Base
      # UNIX domain socket on which the server is listening for connections.
      attr_accessor :socket
      
      def initialize(socket)
        raise PlatformNotSupported, 'UNIX domain sockets not available on Windows' if Thin.win?
        @socket = socket
        super()
      end
      
      # Connect the server
      def connect
        at_exit { remove_socket_file } # In case it crashes
        EventMachine.start_unix_domain_server(@socket, UnixConnection, &method(:initialize_connection))
        # HACK EventMachine.start_unix_domain_server doesn't return the connection signature
        #      so we have to go in the internal stuff to find it.
        @signature = EventMachine.instance_eval{@acceptors.keys.first}
      end
      
      # Stops the server
      def disconnect
        EventMachine.stop_server(@signature)
      end
      
      # Free up resources used by the backend.
      def close
        remove_socket_file
      end
      
      def to_s
        @socket
      end
      
      protected
        def remove_socket_file
          File.delete(@socket) if @socket && File.exist?(@socket)
        end
    end    
  end

  # Connection through a UNIX domain socket.
  class UnixConnection < Connection
    protected
      def socket_address        
        '127.0.0.1' # Unix domain sockets can only be local
      end
  end
end

Version data entries

24 entries across 24 versions & 6 rubygems

Version Path
grockit-thin-0.8.2 lib/thin/backends/unix_server.rb
macournoyer-thin-1.0.1 lib/thin/backends/unix_server.rb
macournoyer-thin-1.1.0 lib/thin/backends/unix_server.rb
michaelyta-thin-1.2.2 lib/thin/backends/unix_server.rb
steamcannon-thin-1.2.8 lib/thin/backends/unix_server.rb
thin-1.2.7 lib/thin/backends/unix_server.rb
thin-1.2.7-x86-mswin32 lib/thin/backends/unix_server.rb
thin-1.2.7-x86-mingw32 lib/thin/backends/unix_server.rb
thin-1.2.6 lib/thin/backends/unix_server.rb
thin-1.2.6-x86-mswin32 lib/thin/backends/unix_server.rb
thin-1.2.6-x86-mingw32 lib/thin/backends/unix_server.rb
middleman-0.10.17 vendor/gems/gems/thin-1.2.5/lib/thin/backends/unix_server.rb
middleman-0.10.16 vendor/gems/gems/thin-1.2.5/lib/thin/backends/unix_server.rb
middleman-0.10.15 vendor/gems/gems/thin-1.2.5/lib/thin/backends/unix_server.rb
middleman-0.10.14 vendor/gems/gems/thin-1.2.5/lib/thin/backends/unix_server.rb
thin-1.2.5 lib/thin/backends/unix_server.rb
thin-1.2.3-x86-mswin32 lib/thin/backends/unix_server.rb
thin-1.2.4-x86-mswin32 lib/thin/backends/unix_server.rb
thin-1.2.4 lib/thin/backends/unix_server.rb
thin-1.2.3 lib/thin/backends/unix_server.rb