Project

General

Profile

Feature #15560

Add support for read/write offsets.

Added by ioquatix (Samuel Williams) 5 months ago. Updated 5 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:91235]

Description

It would be nice if read/write/send/recv/etc methods could accept an offset argument.

e.g.

socket = Socket.new(...)
buffer = String.b

socket.read(1024, buffer)
socket.read(1024, buffer, offset: buffer.bytesize)

The same for write, e.g.

socket = Socket.new(...)
buffer = String.b

amount = socket.write(buffer)
socket.write(buffer, offset: amount)

Could also include "size:" so that we can selectively write parts of the buffer.

History

Updated by shyouhei (Shyouhei Urabe) 5 months ago

I can imagine it is useful for TCPSocket#write to accept only a part of a buffer crafted by somebody else. But I cannot think of any actual use case when #read is useful with that extension. Do you have one?

Updated by ioquatix (Samuel Williams) 5 months ago

It is useful for read when user wants to read some data, and it wasn't enough (e.g. implementing gets) so you need to read some more at the end of what you already have.

Updated by ioquatix (Samuel Williams) 5 months ago

Also, rather than using a keyword argument, it could be a 3rd argument after buffer, since buffer must be supplied in order for this to work.

#4

Updated by ioquatix (Samuel Williams) 5 months ago

  • Target version deleted (2.7)

Also available in: Atom PDF