Properly handle closed sockets and polyfill some more methods
This commit is contained in:
parent
b9e8c5a06f
commit
7c7d2cb50c
@ -115,7 +115,7 @@ class DataCenter
|
|||||||
[
|
[
|
||||||
new Nameserver('https://mozilla.cloudflare-dns.com/dns-query'),
|
new Nameserver('https://mozilla.cloudflare-dns.com/dns-query'),
|
||||||
new Nameserver('https://google.com/resolve', Nameserver::GOOGLE_JSON, ["Host" => "dns.google.com"]),
|
new Nameserver('https://google.com/resolve', Nameserver::GOOGLE_JSON, ["Host" => "dns.google.com"]),
|
||||||
],
|
]
|
||||||
);
|
);
|
||||||
$this->DoHClient = Magic::$altervista || Magic::$zerowebhost ? new Rfc1035StubResolver() : new Rfc8484StubResolver($DoHConfig);
|
$this->DoHClient = Magic::$altervista || Magic::$zerowebhost ? new Rfc1035StubResolver() : new Rfc8484StubResolver($DoHConfig);
|
||||||
$this->NonProxiedDoHClient = Magic::$altervista || Magic::$zerowebhost ? new Rfc1035StubResolver() : new Rfc8484StubResolver($NonProxiedDoHConfig);
|
$this->NonProxiedDoHClient = Magic::$altervista || Magic::$zerowebhost ? new Rfc1035StubResolver() : new Rfc8484StubResolver($NonProxiedDoHConfig);
|
||||||
|
@ -25,6 +25,7 @@ use danog\MadelineProto\Loop\Impl\SignalLoop;
|
|||||||
use danog\MadelineProto\MTProtoTools\Crypt;
|
use danog\MadelineProto\MTProtoTools\Crypt;
|
||||||
use danog\MadelineProto\NothingInTheSocketException;
|
use danog\MadelineProto\NothingInTheSocketException;
|
||||||
use danog\MadelineProto\Tools;
|
use danog\MadelineProto\Tools;
|
||||||
|
use Amp\ByteStream\StreamException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Socket read loop.
|
* Socket read loop.
|
||||||
@ -56,10 +57,11 @@ class ReadLoop extends SignalLoop
|
|||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
$error = yield $this->waitSignal($this->readMessage());
|
$error = yield $this->waitSignal($this->readMessage());
|
||||||
} catch (NothingInTheSocketException $e) {
|
} catch (NothingInTheSocketException|StreamException $e) {
|
||||||
if (isset($connection->old)) {
|
if (isset($connection->old)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$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();
|
yield $connection->reconnect();
|
||||||
continue;
|
continue;
|
||||||
|
@ -24,6 +24,7 @@ use danog\MadelineProto\Loop\Impl\ResumableSignalLoop;
|
|||||||
use danog\MadelineProto\Magic;
|
use danog\MadelineProto\Magic;
|
||||||
use danog\MadelineProto\MTProtoTools\Crypt;
|
use danog\MadelineProto\MTProtoTools\Crypt;
|
||||||
use danog\MadelineProto\Tools;
|
use danog\MadelineProto\Tools;
|
||||||
|
use Amp\ByteStream\StreamException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Socket write loop.
|
* Socket write loop.
|
||||||
@ -64,7 +65,7 @@ class WriteLoop extends ResumableSignalLoop
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$please_wait = yield $this->{$connection->temp_auth_key === null ? 'unencryptedWriteLoopAsync' : 'encryptedWriteLoopAsync'}();
|
$please_wait = yield $this->{$connection->temp_auth_key === null ? 'unencryptedWriteLoopAsync' : 'encryptedWriteLoopAsync'}();
|
||||||
} catch (\Amp\ByteStream\StreamException $e) {
|
} catch (StreamException $e) {
|
||||||
if (isset($connection->old)) {
|
if (isset($connection->old)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ use danog\MadelineProto\Stream\RawStreamInterface;
|
|||||||
use function Amp\Socket\connect;
|
use function Amp\Socket\connect;
|
||||||
use function Amp\Socket\cryptoConnect;
|
use function Amp\Socket\cryptoConnect;
|
||||||
use danog\MadelineProto\Stream\ProxyStreamInterface;
|
use danog\MadelineProto\Stream\ProxyStreamInterface;
|
||||||
|
use Amp\ByteStream\ClosedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default stream wrapper.
|
* Default stream wrapper.
|
||||||
@ -83,6 +84,9 @@ class DefaultStream extends Socket implements RawStreamInterface, ProxyStreamInt
|
|||||||
*/
|
*/
|
||||||
public function write(string $data): Promise
|
public function write(string $data): Promise
|
||||||
{
|
{
|
||||||
|
if (!$this->stream) {
|
||||||
|
throw new ClosedException("MadelineProto stream was disconnected");
|
||||||
|
}
|
||||||
return $this->stream->write($data);
|
return $this->stream->write($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,3 +12,6 @@ if (!function_exists('is_iterable')) {
|
|||||||
return is_array($var) || $var instanceof Traversable;
|
return is_array($var) || $var instanceof Traversable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!function_exists('error_clear_last')) {
|
||||||
|
function error_clear_last() {}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user