Protocol::HTTYSourceProtocolHTTYStream

class Stream

Transport an opaque byte stream after the HTTY bootstrap handshake.

Definitions

def initialize(input, output)

Create a stream on top of raw byte-preserving endpoints.

Signature

parameter input IO

The readable endpoint.

parameter output IO

The writable endpoint.

Implementation

def initialize(input, output)
	@input = input
	@output = output
	@local_closed = false
end

def remote_address

Required by Protocol::HTTP::Peer but not applicable to HTTY, which does not have a concept of remote addresses.

Implementation

def remote_address
	return nil
end

def io

Return the underlying output stream.

Implementation

def io
	@output
end

def read(length = nil)

Read application bytes from the HTTY transport. The HTTP/2 framer always requests exact byte counts (header size, then payload length), so we delegate directly to the underlying input.

Implementation

def read(length = nil)
	@input.read(length)
end

def write(data, flush: false)

Write application bytes after bootstrap.

Signature

returns self
raises IOError

If the local side of the transport is closed.

Implementation

def write(data, flush: false)
	raise IOError, "HTTY stream is closed for writing!" if @local_closed
	
	@output.write(data.to_s.b)
	@output.flush if flush
	
	return self
end

def flush

Flush any buffered output through the underlying stream.

Signature

returns void

Implementation

def flush
	@output.flush
end

def close_write(error = nil)

Close the local write side of this stream abstraction. HTTY does not define a close packet, and closing this object does not close the underlying terminal IO.

Signature

returns void

Implementation

def close_write(error = nil)
	unless @local_closed
		@local_closed = true
		@output.flush
	end
end

def closed?

Check whether the local side of the transport is closed.

Signature

returns bool

True if local writes have been closed.

Implementation

def closed?
	@local_closed
end

def readable?

Check whether the remote side may still provide more data.

Signature

returns bool

True if the remote side has not sent or implied a close.

Implementation

def readable?
	!(@input.respond_to?(:closed?) && @input.closed?)
end