From 4d599e017b5c85addd9b1aae5853eec6b58ded11 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 13 Sep 2019 17:24:52 +0200 Subject: [PATCH] Improve socket management --- src/danog/MadelineProto/Loop/Connection/ReadLoop.php | 9 ++++----- src/danog/MadelineProto/Loop/Connection/WriteLoop.php | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/danog/MadelineProto/Loop/Connection/ReadLoop.php b/src/danog/MadelineProto/Loop/Connection/ReadLoop.php index eb8594ce..2bdb988e 100644 --- a/src/danog/MadelineProto/Loop/Connection/ReadLoop.php +++ b/src/danog/MadelineProto/Loop/Connection/ReadLoop.php @@ -83,8 +83,8 @@ class ReadLoop extends SignalLoop } $API->logger->logger($e); $API->logger->logger("Got nothing in the socket in DC {$datacenter}, reconnecting...", Logger::ERROR); - yield $connection->reconnect(); - continue; + Tools::callForkDefer($connection->reconnect()); + return; } if (\is_int($error)) { @@ -206,10 +206,9 @@ class ReadLoop extends SignalLoop */ $session_id = \substr($decrypted_data, 8, 8); if ($session_id != $connection->session_id) { + $API->logger->logger("Session ID mismatch", Logger::FATAL_ERROR); $connection->resetSession(); - Tools::callForkDefer($connection->reconnect()); - return; - throw new \danog\MadelineProto\Exception('Session id mismatch'); + throw new NothingInTheSocketException(); } $message_id = \substr($decrypted_data, 16, 8); $connection->check_message_id($message_id, ['outgoing' => false, 'container' => false]); diff --git a/src/danog/MadelineProto/Loop/Connection/WriteLoop.php b/src/danog/MadelineProto/Loop/Connection/WriteLoop.php index 7b62e504..46f8720c 100644 --- a/src/danog/MadelineProto/Loop/Connection/WriteLoop.php +++ b/src/danog/MadelineProto/Loop/Connection/WriteLoop.php @@ -91,8 +91,8 @@ class WriteLoop extends ResumableSignalLoop } $API->logger($e); $API->logger->logger("Got nothing in the socket in DC {$datacenter}, reconnecting...", Logger::ERROR); - yield $connection->reconnect(); - continue; + Tools::callForkDefer($connection->reconnect()); + return; } finally { $connection->writing(false); }