Skip to content

Commit

Permalink
[Stream][Buffer] Only check feof on some occasions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cboden committed Jul 9, 2013
1 parent ca24819 commit c212d55
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Buffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ class Buffer extends EventEmitter implements WritableStreamInterface
'file' => '',
'line' => 0,
);
private $meta;

public function __construct($stream, LoopInterface $loop)
{
$this->stream = $stream;
$this->loop = $loop;

if (is_resource($stream)) {
$this->meta = stream_get_meta_data($stream);
}
}

public function isWritable()
Expand Down Expand Up @@ -78,7 +83,7 @@ public function close()

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

return;
Expand Down

0 comments on commit c212d55

Please sign in to comment.