Sha256: 5a5287255545602138d009fd4e853c44883c63ab6f6af61a96e184729e476b54

Contents?: true

Size: 1.55 KB

Versions: 82

Compression:

Stored size: 1.55 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
        old_umask = File.umask(0)
        begin
          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}
        ensure
          File.umask(old_umask)
        end
      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

82 entries across 81 versions & 7 rubygems

Version Path
thin-1.8.2 lib/thin/backends/unix_server.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/2.6.0/gems/thin-1.8.1/lib/thin/backends/unix_server.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.1.0/gems/thin-1.8.1/lib/thin/backends/unix_server.rb
thin-1.8.1 lib/thin/backends/unix_server.rb
thin-1.8.0 lib/thin/backends/unix_server.rb
gross-1.7.2 lib/thin/backends/unix_server.rb
thin-1.7.2 lib/thin/backends/unix_server.rb
thin-1.7.1 lib/thin/backends/unix_server.rb
arcabouco-0.2.13 vendor/bundle/gems/thin-1.7.0/lib/thin/backends/unix_server.rb
thin-1.7.0 lib/thin/backends/unix_server.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/thin-1.6.4/lib/thin/backends/unix_server.rb
classiccms-0.7.5 vendor/bundle/gems/thin-1.3.1/lib/thin/backends/unix_server.rb
classiccms-0.7.4 vendor/bundle/gems/thin-1.3.1/lib/thin/backends/unix_server.rb
classiccms-0.7.3 vendor/bundle/gems/thin-1.3.1/lib/thin/backends/unix_server.rb
thin-1.6.4 lib/thin/backends/unix_server.rb
thin-1.6.3 lib/thin/backends/unix_server.rb
thin-1.6.2 lib/thin/backends/unix_server.rb
thin-1.6.1 lib/thin/backends/unix_server.rb
thin-1.6.0 lib/thin/backends/unix_server.rb
classiccms-0.7.2 vendor/bundle/gems/thin-1.3.1/lib/thin/backends/unix_server.rb