make IO::Handle::error report errors from both input and output streams #17781
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The perl IO SV has slots for an input PerlIO object and an output PerlIO object.
For normal files this is always the same PerlIO object, but for character devices and sockets a second PerlIO object is created for the same fd and stored in the output slot, this allows input and output to be buffered separately.
The IO::Handle::error() method however only checks the input handle, so if there's an error writing to a socket or character device that isn't reflected in the result of calling error() on the handle.
Similarly IO::Handle::clearerr() only clears the error/eof state on the input handle, but for character devices and sockets this meant only half the error state was reset.
This PR adjusts those methods to work on both the input and output streams if they're different.