Allow ctrl-c at any time

This commit is contained in:
Daniil Gentili 2019-09-03 19:03:39 +02:00
parent 848d1f310b
commit 1ba3258581
4 changed files with 27 additions and 3 deletions

View File

@ -305,7 +305,7 @@ class Connection extends Session
*/
public function connect(ConnectionContext $ctx): \Generator
{
$this->API->logger->logger("Trying connection via $ctx", \danog\MadelineProto\Logger::WARNING);
$this->API->logger->logger("Trying connection ({$this->id}) via $ctx", \danog\MadelineProto\Logger::WARNING);
$ctx->setReadCallback([$this, 'haveRead']);

View File

@ -330,6 +330,9 @@ class DataCenterConnection implements JsonSerializable
$this->decWrite = self::WRITE_WEIGHT;
if ($id === -1) {
if ($this->connections) {
$this->disconnect();
}
yield $this->connectMore($count);
} else {
$this->availableConnections[$id] = 0;
@ -423,7 +426,12 @@ class DataCenterConnection implements JsonSerializable
*/
public function even()
{
if (\min($this->availableConnections) < 100) {
$min = \min($this->availableConnections);
if ($min < 50) {
foreach ($this->availableConnections as &$count) {
$count += 50;
}
} else if ($min < 100) {
$max = $this->isMedia() || $this->isCDN() ? $this->API->settings['connection_settings']['media_socket_count']['max'] : 1;
if (\count($this->availableConnections) < $max) {
$this->connectMore(2);

View File

@ -68,7 +68,7 @@ abstract class Loop implements LoopInterface
yield $this->loop();
} finally {
$this->exitedLoop();
$this->API->logger->logger("Exited $this", Logger::ULTRA_VERBOSE);
$this->API->logger->logger("Physically exited $this", Logger::ULTRA_VERBOSE);
//return null;
}
}
@ -76,6 +76,7 @@ abstract class Loop implements LoopInterface
public function exitedLoop()
{
if ($this->count) {
$this->API->logger->logger("Exited $this", Logger::ULTRA_VERBOSE);
$this->count--;
}
}

View File

@ -23,6 +23,10 @@ use Amp\DoH\DoHConfig;
use Amp\DoH\Nameserver;
use Amp\DoH\Rfc8484StubResolver;
use Amp\Loop;
use Amp\Loop\Driver;
use ReflectionClass;
use ReflectionObject;
use function Amp\ByteStream\getInputBufferStream;
use function Amp\ByteStream\getStdin;
use function Amp\Dns\resolver;
@ -234,6 +238,17 @@ class Magic
self::$signaled = true;
getStdin()->unreference();
getInputBufferStream()->unreference();
if ($code !== 0) {
$driver = Loop::get();
$reflectionClass = new ReflectionClass(Driver::class);
$reflectionProperty = $reflectionClass->getProperty('watchers');
$reflectionProperty->setAccessible(true);
foreach (array_keys($reflectionProperty->getValue($driver)) as $key) {
$driver->unreference($key);
}
}
Loop::stop();
die($code);
}
}