Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Disconnect and emit error on unrecoverable errors #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"require": {
"php": "^7.1 || ^8.0",
"react/event-loop": "^1.0 || ^0.5 || ^0.4",
"react/promise": "~2.2"
"react/promise": "^3 || ~2.2",
"evenement/evenement": "^3.0"
},
"require-dev": {
"ext-pcntl": "*",
Expand Down
3 changes: 2 additions & 1 deletion src/Bunny/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Bunny\Protocol\MethodFrame;
use Bunny\Protocol\ProtocolReader;
use Bunny\Protocol\ProtocolWriter;
use Evenement\EventEmitter;
use InvalidArgumentException;
use React\Promise;

Expand All @@ -29,7 +30,7 @@
*
* @author Jakub Kulhan <jakub.kulhan@gmail.com>
*/
abstract class AbstractClient
abstract class AbstractClient extends EventEmitter
{

use ClientMethods;
Expand Down
35 changes: 20 additions & 15 deletions src/Bunny/Async/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,26 +299,31 @@ public function onDataAvailable()
{
$this->read();

while (($frame = $this->reader->consumeFrame($this->readBuffer)) !== null) {
foreach ($this->awaitCallbacks as $k => $callback) {
if ($callback($frame) === true) {
unset($this->awaitCallbacks[$k]);
continue 2; // CONTINUE WHILE LOOP
try {
while (($frame = $this->reader->consumeFrame($this->readBuffer)) !== null) {
foreach ($this->awaitCallbacks as $k => $callback) {
if ($callback($frame) === true) {
unset($this->awaitCallbacks[$k]);
continue 2; // CONTINUE WHILE LOOP
}
}
}

if ($frame->channel === 0) {
$this->onFrameReceived($frame);
if ($frame->channel === 0) {
$this->onFrameReceived($frame);

} else {
if (!isset($this->channels[$frame->channel])) {
throw new ClientException(
"Received frame #{$frame->type} on closed channel #{$frame->channel}."
);
}
} else {
if (!isset($this->channels[$frame->channel])) {
throw new ClientException(
"Received frame #{$frame->type} on closed channel #{$frame->channel}."
);
}

$this->channels[$frame->channel]->onFrameReceived($frame);
$this->channels[$frame->channel]->onFrameReceived($frame);
}
}
} catch (\Throwable $error) {
$this->disconnect();
$this->emit('error', [$error]);
}
}

Expand Down