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()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
socket_close($this->sock);
|
socket_close($this->sock);
|
||||||
|
unset($this->sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setOption(int $level, int $name, $value)
|
public function setOption(int $level, int $name, $value)
|
||||||
|
@ -194,6 +194,7 @@ class Connection
|
|||||||
public function close_and_reopen()
|
public function close_and_reopen()
|
||||||
{
|
{
|
||||||
$this->__destruct();
|
$this->__destruct();
|
||||||
|
\danog\MadelineProto\Logger::log(['Reopening...'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
|
||||||
$this->must_open = true;
|
$this->must_open = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,10 +215,6 @@ class Connection
|
|||||||
|
|
||||||
public function write($what, $length = null)
|
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) {
|
if ($length !== null) {
|
||||||
$what = substr($what, 0, $length);
|
$what = substr($what, 0, $length);
|
||||||
} else {
|
} else {
|
||||||
@ -260,11 +257,7 @@ class Connection
|
|||||||
throw new \danog\MadelineProto\NothingInTheSocketException(\danog\MadelineProto\Lang::$current_lang['nothing_in_socket']);
|
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);
|
return @$this->obfuscated['decryption']->encrypt($packet);
|
||||||
case 'tcp_abridged':
|
case 'tcp_abridged':
|
||||||
@ -279,11 +272,6 @@ class Connection
|
|||||||
throw new \danog\MadelineProto\NothingInTheSocketException(\danog\MadelineProto\Lang::$current_lang['nothing_in_socket']);
|
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;
|
return $packet;
|
||||||
case 'udp':
|
case 'udp':
|
||||||
@ -342,6 +330,10 @@ class Connection
|
|||||||
|
|
||||||
public function send_message($message)
|
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) {
|
switch ($this->protocol) {
|
||||||
case 'tcp_full':
|
case 'tcp_full':
|
||||||
$this->out_seq_no++;
|
$this->out_seq_no++;
|
||||||
|
@ -185,7 +185,7 @@ trait CallHandler
|
|||||||
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
|
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
|
||||||
$last_error = 'Nothing in the socket';
|
$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);
|
\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) {
|
if ($canunset) {
|
||||||
|
@ -205,7 +205,7 @@ trait PeerHandler
|
|||||||
if (isset($this->chats[$id])) {
|
if (isset($this->chats[$id])) {
|
||||||
return $this->gen_all($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);
|
$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']) {
|
if (isset($dbres['ok']) && $dbres['ok']) {
|
||||||
$this->resolve_username('@'.$dbres['result']);
|
$this->resolve_username('@'.$dbres['result']);
|
||||||
|
Loading…
Reference in New Issue
Block a user