diff --git a/src/Socket.php b/src/Socket.php
index 21c3573d..a485669d 100644
--- a/src/Socket.php
+++ b/src/Socket.php
@@ -119,8 +119,8 @@ If not, see .
{
$packet = '';
$try = 0;
- while (strlen($packet) < $length) {
- $read = stream_get_contents($this->sock, $length - strlen($packet));
+ while (($current_length = strlen($packet)) < $length) {
+ $read = stream_get_contents($this->sock, $length - $current_length);
if ($read === false || (strlen($read) === 0 && $try > 10)) {
throw new \danog\MadelineProto\NothingInTheSocketException('Nothing in the socket!');
}
@@ -139,10 +139,15 @@ If not, see .
$buffer = substr($buffer, 0, $length);
}
- $wrote = 0;
- if (($wrote += fwrite($this->sock, $buffer, $length)) !== $length) {
- while (($wrote += fwrite($this->sock, substr($buffer, $wrote), $length - $wrote)) !== $length) {
+ $try = 0;
+ $wrote = fwrite($this->sock, $buffer, $length);
+ while ($wrote < $length) {
+ $wrote_now = fwrite($this->sock, substr($buffer, $wrote), $length - $wrote);
+ if ($wrote_now === false || ($wrote_now === 0 && $try > 10)) {
+ throw new \danog\MadelineProto\NothingInTheSocketException('Nothing could be written in the socket!');
}
+ $wrote += $wrote_now;
+ $try++;
}
return $wrote;
@@ -306,10 +311,16 @@ if (!extension_loaded('pthreads')) {
$buffer = substr($buffer, 0, $length);
}
- $wrote = 0;
- if (($wrote += socket_write($this->sock, $buffer, $length)) !== $length) {
- while (($wrote += socket_write($this->sock, substr($buffer, $wrote), $length - $wrote)) !== $length) {
+
+ $try = 0;
+ $wrote = socket_write($this->sock, $buffer, $length);
+ while ($wrote < $length) {
+ $wrote_now = socket_write($this->sock, substr($buffer, $wrote), $length - $wrote);
+ if ($wrote_now === false || ($wrote_now === 0 && $try > 10)) {
+ throw new \danog\MadelineProto\NothingInTheSocketException('Nothing could be written in the socket!');
}
+ $wrote += $wrote_now;
+ $try++;
}
return $wrote;
diff --git a/src/danog/MadelineProto/CombinedEventHandler.php b/src/danog/MadelineProto/CombinedEventHandler.php
index 3f3728fe..adb0fe53 100644
--- a/src/danog/MadelineProto/CombinedEventHandler.php
+++ b/src/danog/MadelineProto/CombinedEventHandler.php
@@ -27,12 +27,11 @@ abstract class CombinedEventHandler
final public function __sleep()
{
- $keys = get_object_vars($this);
+ $keys = method_exists($this, '__magic_sleep') ? $this->__magic_sleep() : get_object_vars($this);
unset($keys['CombinedAPI']);
foreach ($this->CombinedAPI->instance_paths as $path) {
unset($keys[$path]);
}
-
return array_keys($keys);
}
diff --git a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php
index 4c98177f..9a21f3d7 100644
--- a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php
+++ b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php
@@ -344,6 +344,9 @@ trait ResponseHandler
}
switch ($server_answer['error_code']) {
case 500:
+ if ($server_answer['error_message'] === 'MSG_WAIT_FAILED') {
+ throw new \danog\MadelineProto\RPCErrorException($server_answer['error_message'], $server_answer['error_code']);
+ }
throw new \danog\MadelineProto\Exception('Re-executing query after server error...');
case 303:
$this->datacenter->curdc = $aargs['datacenter'] = (int) preg_replace('/[^0-9]+/', '', $server_answer['error_message']);
diff --git a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php
index cb0f4f29..e3be3f9f 100644
--- a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php
+++ b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php
@@ -605,6 +605,10 @@ trait UpdateHandler
if (isset($this->temp_requested_secret_chats[$update['chat']['id']])) {
unset($this->temp_requested_secret_chats[$update['chat']['id']]);
}
+ if (isset($this->temp_rekeyed_secret_chats[$update['chat']['id']])) {
+ unset($this->temp_rekeyed_secret_chats[$update['chat']['id']]);
+ }
+
break;
case 'encryptedChat':
$this->logger->logger('Completing creation of secret chat '.$update['chat']['id'], \danog\MadelineProto\Logger::NOTICE);