class

HT2::BufferedSocket

Inherits IO < Reference < Object

BufferedSocket wraps an IO to provide peeking functionality without consuming bytes from the underlying socket. This is essential for connection type detection in h2c.

Constructors

new(io : IO, initial_buffer_size : Int32 = 1024)
Source

Instance methods

close

Closes this IO.

IO defines this is a no-op method, but including types may override.

Source
closed?

Returns true if this IO is closed.

IO defines returns false, but including types may override.

Source
flush

Flushes buffered data, if any.

IO defines this is a no-op method, but including types may override.

Source
peek(n : Int32, timeout : Time::Span | Nil = nil) : Bytes

Peek at the first n bytes without consuming them

Source
read(slice : Bytes) : Int32

Read bytes from the buffer first, then from the underlying IO

Source
read_fully(slice : Bytes) : Int32

Override read_fully to ensure it works correctly with buffering

Source
write(slice : Bytes) : Nil

Writes the contents of slice into this IO.

io = IO::Memory.new
slice = Bytes.new(4) { |i| ('a'.ord + i).to_u8 }
io.write(slice)
io.to_s # => "abcd"
Source