Is it possible to read from a TCP socket at most n
bytes? bytes_read = socket.read(buffer)
reads at most buffer.size
bytes, but that’s just too much in certain cases. #read
unfortunately does not accept any max-size param.
If this is not possible, can I have a buffer (something like Bytes.new(4096)
) and limit it’s size with a cast-like method? Something like buffer.as(... a 512 bytes long buffer...)
, buffer.first_slice_of(512)
or buffer.shrinked_to(512)
or something like this, that is essentially the same memory, but looks like a smaller sized buffer to read
?