-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: io: add WriterTo
to PipeReader
and ReaderFrom
to PipeWriter
#54877
Comments
This doesn't seem to match the general model for |
I don't understand what this means. I shouldn't have assumed this was obvious, but calls to |
What I mean is that |
I think I get it now, it's that one call to write will always match one call to read (assuming the read buffer is big enough). That seems to be a very special detail to me. When I use it, it's because I have poorly architectured code, one function wants to write the other one want to read (imagine using So I just throw an However Adding |
There is opportunities to skip synchronization events, allocations and maybe even do some zero copies (if
WriteTo
andReadFrom
are called concurrently).If
ReadFrom
is called this would allowRead
to acquire a reference to theReader
passed in and pass the buffer slice to the reader directly (skipping a possible allocation that would have been required to copy data fromReader
toPipeWriter
).If
WriteTo
is called this would allowWrite
to acquire a reference to theWriter
passed in and pass the buffer slice to the reader directly (skipping a possible allocation that would have required to copy data fromPipeReader
toWriter
).If
ReadFrom
andWriteTo
are called this would allow to callio.Copy
(or equivalent reusing a buffer) to maybe do a zero copy between theWriter
andReader
.The implementation would need to account for the fact that
ReadFrom
can be called multiple times andWriteTo
need to waits until the pipe is closed, but nothing that cannot be done.The extra channels required to pass the
Writer
andReader
around might be much in term of extra allocations, I guess async
based implementation (instead of channels) would be better (as it would just embed all synchronization primitives into thepipe
struct).The text was updated successfully, but these errors were encountered: