Skip to content

Commit 0c8eaec

Browse files
committed
Merge pull request #246 from jmalloc/stream-drain-event
[Stream] Pass the stream as final parameter on 'drain'.
2 parents 37481ec + c395376 commit 0c8eaec

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

src/React/Stream/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

src/React/Stream/Stream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct($stream, LoopInterface $loop)
2727
});
2828

2929
$this->buffer->on('drain', function () {
30-
$this->emit('drain');
30+
$this->emit('drain', array($this));
3131
});
3232

3333
$this->resume();

src/React/Stream/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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy