Skip to content

net: no way to use sendfile with offset and count #9113

@jbardin

Description

@jbardin
A go TCP server can efficiently server files to clients using the ReadFrom method, but
if the protocol allows partial files, e.g. HTTP Range requests, we have to fallback to
copying all the data again for each connection.

Currently sendfile is only accessible by calling *TCPConn.ReadFrom(r io.Reader), with no
way to set the offset and count. Internally, sendfile uses to the netFD writelock and
file descriptor. Doing this outside of the net package is awkward and requires putting
the connection into blocking mode.

One option is to special case an io.SectionReader in the sendfile implementation, though
this requires modifying SectionReader in a way to expose the underlying io.Reader,
offset, and count fields.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions