Sha256: 3318d8152f9e5a0190052d92b08f1e5130bfbdb28938344e1b67d64e5ea1886b

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module PuppetEditorServices
  module Connection
    class Base
      attr_reader :server, :protocol

      def initialize(server)
        @server = server
        @protocol = server.protocol_options[:class].new(self)
      end

      # Override this method
      # @api public
      def error?
        false
      end

      # Override this method
      # @api public
      def send_data(_data)
        false
      end

      # Shouldn't need to override this method
      # @api public
      def receive_data(data)
        @protocol.receive_data(data)
      rescue StandardError => e
        server.log("Protocol #{@protocol.class} raised error #{e}: #{e.backtrace}")
      end

      # Override this method
      # @api public
      def close_after_writing
        true
      end

      # Override this method
      # @api public
      def close
        true
      end

      # Override this method if needed
      # @api public
      def post_init
        server.log("Client #{id} has connected to the server")
      end

      # Override this method if needed
      # @api public
      def unbind
        server.log("Client #{id} has disconnected from the server")
      end

      def id
        object_id.to_s
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puppet-editor-services-2.0.4 lib/puppet_editor_services/connection/base.rb