Skip to content

Commit

Permalink
Merge 868846b into d5cd42a
Browse files Browse the repository at this point in the history
  • Loading branch information
psafarov committed May 6, 2019
2 parents d5cd42a + 868846b commit 6e0c1db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions lib/ResourceOutputStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ public function __construct($stream, int $chunkSize = null)
continue;
}

if (!\is_resource($stream) || @\feof($stream)) {
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.
// Use conditional, because PHP doesn't like getting null passed
if ($chunkSize) {
Expand All @@ -101,6 +97,11 @@ public function __construct($stream, int $chunkSize = null)

$emptyWrites = 0;

if (!@\fflush($stream)) {
throw new StreamException("Failed to flush data from buffer");
}


if ($length > $written) {
$data = \substr($data, $written);
$writes->unshift([$data, $written + $previous, $deferred]);
Expand Down Expand Up @@ -179,10 +180,6 @@ private function send(string $data, bool $end = false): Promise
return new Success(0);
}

if (!\is_resource($this->resource) || @\feof($this->resource)) {
return new Failure(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.
// Use conditional, because PHP doesn't like getting null passed.
if ($this->chunkSize) {
Expand All @@ -194,6 +191,9 @@ private function send(string $data, bool $end = false): Promise
\assert($written !== false, "Trying to write on a previously fclose()'d resource. Do NOT manually fclose() resources the loop still has a reference to.");

if ($length === $written) {
if (!@\fflush($this->resource)) {
return new Failure(new StreamException("Failed to flush data from buffer"));
}
if ($end) {
$this->close();
}
Expand Down
6 changes: 3 additions & 3 deletions test/ResourceOutputStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testBrokenPipe()
\fclose($b);

$this->expectException(StreamException::class);
$this->expectExceptionMessage("The stream was closed by the peer");
$this->expectExceptionMessage("Failed to write to stream after multiple attempts");
wait($stream->write("foobar"));
}

Expand All @@ -60,7 +60,7 @@ public function testClosedRemoteSocket()
\fclose($b);

$this->expectException(StreamException::class);
$this->expectExceptionMessage("The stream was closed by the peer");
$this->expectExceptionMessage("Failed to write to stream after multiple attempts");

// The first write still succeeds somehow...
wait($stream->write("foobar"));
Expand Down Expand Up @@ -88,7 +88,7 @@ public function testClosedRemoteSocketWithFork()
\fclose($b);

$this->expectException(StreamException::class);
$this->expectExceptionMessage("The stream was closed by the peer");
$this->expectExceptionMessage("Failed to write to stream after multiple attempts");

try {
// The first write still succeeds somehow...
Expand Down

0 comments on commit 6e0c1db

Please sign in to comment.