Skip to content

Commit c342963

Browse files
committed
Merge pull request #74 from react-php/fix-buffer-feof
Emit correct exception when trying to write to closed stream
2 parents 5bf0443 + f5a20c5 commit c342963

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Buffer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,19 @@ public function close()
7777

7878
public function handleWrite()
7979
{
80+
if (!is_resource($this->stream) || feof($this->stream)) {
81+
$this->emit('error', array(new \RuntimeException('Tried to write to closed or invalid stream.')));
82+
83+
return;
84+
}
85+
8086
set_error_handler(array($this, 'errorHandler'));
8187

8288
$sent = fwrite($this->stream, $this->data);
8389

8490
restore_error_handler();
8591

86-
if (false === $sent || feof($this->stream)) {
92+
if (false === $sent) {
8793
$this->emit('error', array(new \ErrorException(
8894
$this->lastError['message'],
8995
0,

0 commit comments

Comments
 (0)