Skip to content

Commit c212d55

Browse files
committed
[Stream][Buffer] Only check feof on some occasions
If a TCP endpoint triggers a socket close handshake the other endpoint is still allowed to send data if the connection is open and should send a closing handshake asap. feof detected the socket was closed for reading but told the write buffer is was closed entirely. We can't seem to determine the difference in PHP so we're only checking if it's a generic_socket which seems to satisfy the requirements.
1 parent ca24819 commit c212d55

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Buffer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ class Buffer extends EventEmitter implements WritableStreamInterface
2121
'file' => '',
2222
'line' => 0,
2323
);
24+
private $meta;
2425

2526
public function __construct($stream, LoopInterface $loop)
2627
{
2728
$this->stream = $stream;
2829
$this->loop = $loop;
30+
31+
if (is_resource($stream)) {
32+
$this->meta = stream_get_meta_data($stream);
33+
}
2934
}
3035

3136
public function isWritable()
@@ -78,7 +83,7 @@ public function close()
7883

7984
public function handleWrite()
8085
{
81-
if (!is_resource($this->stream) || feof($this->stream)) {
86+
if (!is_resource($this->stream) || ('generic_socket' === $this->meta['stream_type'] && feof($this->stream))) {
8287
$this->emit('error', array(new \RuntimeException('Tried to write to closed or invalid stream.')));
8388

8489
return;

0 commit comments

Comments
 (0)