Skip to content

Commit a4de87e

Browse files
committed
Added stream parameter to emitted events on Buffer and ThroughStream.
1 parent f5ced35 commit a4de87e

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

Buffer.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ public function close()
7878
$this->listening = false;
7979
$this->data = '';
8080

81-
$this->emit('close');
81+
$this->emit('close', [$this]);
8282
}
8383

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

8989
return;
9090
}
@@ -96,20 +96,23 @@ public function handleWrite()
9696
restore_error_handler();
9797

9898
if (false === $sent) {
99-
$this->emit('error', array(new \ErrorException(
100-
$this->lastError['message'],
101-
0,
102-
$this->lastError['number'],
103-
$this->lastError['file'],
104-
$this->lastError['line']
105-
)));
99+
$this->emit('error', array(
100+
new \ErrorException(
101+
$this->lastError['message'],
102+
0,
103+
$this->lastError['number'],
104+
$this->lastError['file'],
105+
$this->lastError['line']
106+
),
107+
$this
108+
));
106109

107110
return;
108111
}
109112

110113
$len = strlen($this->data);
111114
if ($len >= $this->softLimit && $len - $sent < $this->softLimit) {
112-
$this->emit('drain');
115+
$this->emit('drain', [$this]);
113116
}
114117

115118
$this->data = (string) substr($this->data, $sent);
@@ -118,7 +121,7 @@ public function handleWrite()
118121
$this->loop->removeWriteStream($this->stream);
119122
$this->listening = false;
120123

121-
$this->emit('full-drain');
124+
$this->emit('full-drain', [$this]);
122125
}
123126
}
124127

ThroughStream.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ public function filter($data)
1919

2020
public function write($data)
2121
{
22-
$this->readable->emit('data', array($this->filter($data)));
22+
$this->readable->emit('data', array($this->filter($data), $this));
2323
}
2424

2525
public function end($data = null)
2626
{
2727
if (null !== $data) {
28-
$this->readable->emit('data', array($this->filter($data)));
28+
$this->readable->emit('data', array($this->filter($data), $this));
2929
}
3030

3131
$this->writable->end($data);

0 commit comments

Comments
 (0)