Releases: djherbis/nio
Go module support
Unblocking Write
I made CloseWithError work more similarly to io.Pipe(). CloseWithError effects the error with which the other end of the pipe will return, the same side will return io.ErrClosedPipe.
Also, Close() called concurrently with a Write should cause it to unblock and return (with an error).
Previously, when Closing a concurrent Write would continue to attempt to write to the buffer until successful (leading to it blocking indefinitely if you stopped reading data off the buffer). Now if the writer is awaiting space in the buffer, and is canceled via Close(), it may or may not add the pending data to the buffer, but will return an appropriate error if it fails to add it and return promptly.
Code Coverage 100%
Simplified the code for PipeWriter.Write and increased code coverage to 100%.
Logical Race Fix
Big thanks to @danp for finding and fixing a race
toctou race between:
- check: if a write is too large to fit in the remaining space in a buffer
- use: write to the buffer, capping the write at the size of the gap
Since we blocked on a zero-sized gap before doing the write, it's possible that the gap could have grown larger than the write, causing us to slice the write past it's boundaries!
Exposing PipeReader & PipeWriter
Now PipeReader and PipeWriter are exposed like in io.Pipe() and CloseWithError is accessible.
Thanks to @FiloSottile for the change.