mirror of
https://github.com/danog/byte-stream.git
synced 2024-11-26 11:54:54 +01:00
Check EOF before writing as some writes in macOS are not reported as error otherwise
See Amp\ByteStream\Test\ResourceOutputStreamTest::testClosedRemoteSocketWithFork(), which fails without this on macOS.
This commit is contained in:
parent
90e8097b52
commit
29c78480dc
@ -71,7 +71,7 @@ final class ResourceOutputStream implements OutputStream
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!\is_resource($stream)) {
|
||||
if (!\is_resource($stream) || (($metaData = @\stream_get_meta_data($stream)) && $metaData['eof'])) {
|
||||
throw new StreamException("The stream was closed by the peer");
|
||||
}
|
||||
|
||||
@ -87,11 +87,6 @@ final class ResourceOutputStream implements OutputStream
|
||||
|
||||
// Broken pipes between processes on macOS/FreeBSD do not detect EOF properly.
|
||||
if ($written === 0) {
|
||||
$metaData = @\stream_get_meta_data($stream);
|
||||
if (!\is_resource($stream) || ($metaData && $metaData['eof'])) {
|
||||
throw new StreamException("The stream was closed by the peer");
|
||||
}
|
||||
|
||||
if ($emptyWrites++ > self::MAX_CONSECUTIVE_EMPTY_WRITES) {
|
||||
$message = "Failed to write to stream after multiple attempts";
|
||||
if ($error = \error_get_last()) {
|
||||
@ -184,8 +179,8 @@ final class ResourceOutputStream implements OutputStream
|
||||
return new Success(0);
|
||||
}
|
||||
|
||||
if (!\is_resource($this->resource)) {
|
||||
return new Failure(new StreamException("The stream was closed by the peer"));
|
||||
if (!\is_resource($this->resource) || (($metaData = @\stream_get_meta_data($this->resource)) && $metaData['eof'])) {
|
||||
throw new StreamException("The stream was closed by the peer");
|
||||
}
|
||||
|
||||
// Error reporting suppressed since fwrite() emits E_WARNING if the pipe is broken or the buffer is full.
|
||||
|
Loading…
Reference in New Issue
Block a user