Fix nothing in the socket exceptions, memory leaks, peer handler issues
This commit is contained in:
parent
05aa720c5d
commit
214823f0c0
@ -132,6 +132,7 @@ if (!extension_loaded('pthreads')) {
|
||||
public function __destruct()
|
||||
{
|
||||
socket_close($this->sock);
|
||||
unset($this->sock);
|
||||
}
|
||||
|
||||
public function setOption(int $level, int $name, $value)
|
||||
|
@ -194,6 +194,7 @@ class Connection
|
||||
public function close_and_reopen()
|
||||
{
|
||||
$this->__destruct();
|
||||
\danog\MadelineProto\Logger::log(['Reopening...'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
|
||||
$this->must_open = true;
|
||||
}
|
||||
|
||||
@ -214,10 +215,6 @@ class Connection
|
||||
|
||||
public function write($what, $length = null)
|
||||
{
|
||||
if ($this->must_open) {
|
||||
$this->__construct($this->proxy, $this->extra, $this->ip, $this->port, $this->protocol, $this->timeout, $this->ipv6);
|
||||
$this->must_open = false;
|
||||
}
|
||||
if ($length !== null) {
|
||||
$what = substr($what, 0, $length);
|
||||
} else {
|
||||
@ -260,11 +257,7 @@ class Connection
|
||||
throw new \danog\MadelineProto\NothingInTheSocketException(\danog\MadelineProto\Lang::$current_lang['nothing_in_socket']);
|
||||
}
|
||||
}
|
||||
if (strlen($packet) !== $length) {
|
||||
$this->close_and_reopen();
|
||||
|
||||
throw new Exception(sprintf(\danog\MadelineProto\Lang::$current_lang['wrong_length_read'], $length, strlen($packet)));
|
||||
}
|
||||
|
||||
return @$this->obfuscated['decryption']->encrypt($packet);
|
||||
case 'tcp_abridged':
|
||||
@ -279,11 +272,6 @@ class Connection
|
||||
throw new \danog\MadelineProto\NothingInTheSocketException(\danog\MadelineProto\Lang::$current_lang['nothing_in_socket']);
|
||||
}
|
||||
}
|
||||
if (strlen($packet) !== $length) {
|
||||
$this->close_and_reopen();
|
||||
|
||||
throw new Exception(sprintf(\danog\MadelineProto\Lang::$current_lang['wrong_length_read'], $length, strlen($packet)));
|
||||
}
|
||||
|
||||
return $packet;
|
||||
case 'udp':
|
||||
@ -342,6 +330,10 @@ class Connection
|
||||
|
||||
public function send_message($message)
|
||||
{
|
||||
if ($this->must_open) {
|
||||
$this->__construct($this->proxy, $this->extra, $this->ip, $this->port, $this->protocol, $this->timeout, $this->ipv6);
|
||||
$this->must_open = false;
|
||||
}
|
||||
switch ($this->protocol) {
|
||||
case 'tcp_full':
|
||||
$this->out_seq_no++;
|
||||
|
@ -185,7 +185,7 @@ trait CallHandler
|
||||
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
|
||||
$last_error = 'Nothing in the socket';
|
||||
\danog\MadelineProto\Logger::log(['An error getting response of method '.$method.': '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...'], \danog\MadelineProto\Logger::WARNING);
|
||||
continue 2;
|
||||
continue;//2;
|
||||
}
|
||||
}
|
||||
if ($canunset) {
|
||||
|
@ -205,7 +205,7 @@ trait PeerHandler
|
||||
if (isset($this->chats[$id])) {
|
||||
return $this->gen_all($this->chats[$id]);
|
||||
}
|
||||
if (!isset($this->settings['pwr']['requests']) || $this->settings['pwr']['requests'] === true) {
|
||||
if (!isset($this->settings['pwr']['requests']) || $this->settings['pwr']['requests'] === true && $recursive) {
|
||||
$dbres = json_decode(@file_get_contents('https://id.pwrtelegram.xyz/db/getusername?id='.$id, false, stream_context_create(['http' => ['timeout' => 2]])), true);
|
||||
if (isset($dbres['ok']) && $dbres['ok']) {
|
||||
$this->resolve_username('@'.$dbres['result']);
|
||||
|
Loading…
Reference in New Issue
Block a user