Skip to content

Commit

Permalink
Merge branch 'refs/heads/0.3' into 0.4
Browse files Browse the repository at this point in the history
Conflicts:
	CHANGELOG.md
	src/Stream/Buffer.php
  • Loading branch information
cboden committed Mar 30, 2014
2 parents 16b05e9 + feef566 commit 9db28e8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Buffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Evenement\EventEmitter;
use React\EventLoop\LoopInterface;
use React\Stream\WritableStreamInterface;

/** @event full-drain */
class Buffer extends EventEmitter implements WritableStreamInterface
Expand All @@ -21,16 +20,11 @@ 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 @@ -83,8 +77,8 @@ public function close()

public function handleWrite()
{
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.'), $this));
if (!is_resource($this->stream)) {
$this->emit('error', array(new \RuntimeException('Tried to write to invalid stream.'), $this));

return;
}
Expand All @@ -110,6 +104,12 @@ public function handleWrite()
return;
}

if (0 === $sent && feof($this->stream)) {
$this->emit('error', array(new \RuntimeException('Tried to write to closed stream.'), $this));

return;
}

$len = strlen($this->data);
if ($len >= $this->softLimit && $len - $sent < $this->softLimit) {
$this->emit('drain', [$this]);
Expand Down

0 comments on commit 9db28e8

Please sign in to comment.