Sha256: 77e402b999b8681ce01a5b9ea8a2a8a8fda6147f2aadb7a8f54fa8c725ef82f4

Contents?: true

Size: 1.24 KB

Versions: 9

Compression:

Stored size: 1.24 KB

Contents

module ASIR
  class Transport
    # !SLIDE
    # Stream Transport
    #
    # Base class handles Messages on a stream.
    # Stream Transports require a Coder that encodes to and from String payloads.
    class Stream < self

      # !SLIDE
      # Serve all Messages from a stream.
      def serve_stream! in_stream, out_stream
        with_server_signals! do
          @running = true
          _serve_stream! in_stream, out_stream
        end
      end

      def _serve_stream! in_stream, out_stream
        while @running && ! stream_eof?(in_stream)
          begin
            serve_stream_message! in_stream, out_stream
          rescue *Error::Unrecoverable.modules
            raise
          rescue Error::Terminate => err
            @running = false
            _log [ :serve_stream_terminate, err ]
          rescue ::Exception => err
            _log [ :serve_stream_error, err, err.backtrace ]
            raise err
          end
        end
      end

      # Subclasses can override this method.
      def stream_eof? stream
        stream.eof?
      end

      # !SLIDE
      # Serve a Message from a stream.
      def serve_stream_message! in_stream, out_stream
        serve_message! in_stream, out_stream
      end
    end
    # !SLIDE END
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
asir-1.2.11 lib/asir/transport/stream.rb
asir-1.2.10 lib/asir/transport/stream.rb
asir-1.2.9 lib/asir/transport/stream.rb
asir-1.2.8 lib/asir/transport/stream.rb
asir-1.2.7 lib/asir/transport/stream.rb
asir-1.2.6 lib/asir/transport/stream.rb
asir-1.2.5 lib/asir/transport/stream.rb
asir-1.2.3 lib/asir/transport/stream.rb
asir-1.2.2 lib/asir/transport/stream.rb