Improve socket management

This commit is contained in:
Daniil Gentili 2019-09-13 17:24:52 +02:00
parent aff46a1cc3
commit 4d599e017b
2 changed files with 6 additions and 7 deletions

View File

@ -83,8 +83,8 @@ class ReadLoop extends SignalLoop
} }
$API->logger->logger($e); $API->logger->logger($e);
$API->logger->logger("Got nothing in the socket in DC {$datacenter}, reconnecting...", Logger::ERROR); $API->logger->logger("Got nothing in the socket in DC {$datacenter}, reconnecting...", Logger::ERROR);
yield $connection->reconnect(); Tools::callForkDefer($connection->reconnect());
continue; return;
} }
if (\is_int($error)) { if (\is_int($error)) {
@ -206,10 +206,9 @@ class ReadLoop extends SignalLoop
*/ */
$session_id = \substr($decrypted_data, 8, 8); $session_id = \substr($decrypted_data, 8, 8);
if ($session_id != $connection->session_id) { if ($session_id != $connection->session_id) {
$API->logger->logger("Session ID mismatch", Logger::FATAL_ERROR);
$connection->resetSession(); $connection->resetSession();
Tools::callForkDefer($connection->reconnect()); throw new NothingInTheSocketException();
return;
throw new \danog\MadelineProto\Exception('Session id mismatch');
} }
$message_id = \substr($decrypted_data, 16, 8); $message_id = \substr($decrypted_data, 16, 8);
$connection->check_message_id($message_id, ['outgoing' => false, 'container' => false]); $connection->check_message_id($message_id, ['outgoing' => false, 'container' => false]);

View File

@ -91,8 +91,8 @@ class WriteLoop extends ResumableSignalLoop
} }
$API->logger($e); $API->logger($e);
$API->logger->logger("Got nothing in the socket in DC {$datacenter}, reconnecting...", Logger::ERROR); $API->logger->logger("Got nothing in the socket in DC {$datacenter}, reconnecting...", Logger::ERROR);
yield $connection->reconnect(); Tools::callForkDefer($connection->reconnect());
continue; return;
} finally { } finally {
$connection->writing(false); $connection->writing(false);
} }