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)
SourceInstance methods
closed?
Returns true if this IO is closed.
IO defines returns false, but including types may override.
flush
Flushes buffered data, if any.
IO defines this is a no-op method, but including types may override.
io
Sourcepeek(n : Int32, timeout : Time::Span | Nil = nil) : Bytes
Peek at the first n bytes without consuming them
read_fully(slice : Bytes) : Int32
Override read_fully to ensure it works correctly with buffering
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"