Browse Source

Updated Swoole TcpConnection

twomiao 2 years ago
parent
commit
d9e2be02ac
2 changed files with 10 additions and 4 deletions
  1. 8 2
      src/Connection/TcpConnection.php
  2. 2 2
      src/Events/Swoole.php

+ 8 - 2
src/Connection/TcpConnection.php

@@ -22,6 +22,7 @@ use Workerman\Events\EventInterface;
 use Workerman\Protocols\Http\Request;
 use Workerman\Protocols\ProtocolInterface;
 use Workerman\Worker;
+
 use function ceil;
 use function count;
 use function fclose;
@@ -45,6 +46,7 @@ use function strrchr;
 use function strrpos;
 use function substr;
 use function var_export;
+
 use const PHP_INT_MAX;
 use const STREAM_CRYPTO_METHOD_SSLv23_CLIENT;
 use const STREAM_CRYPTO_METHOD_SSLv23_SERVER;
@@ -352,7 +354,7 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
         $this->maxPackageSize = self::$defaultMaxPackageSize;
         $this->remoteAddress = $remoteAddress;
         static::$connections[$this->id] = $this;
-        $this->context = new stdClass;
+        $this->context = new stdClass();
     }
 
     /**
@@ -388,7 +390,11 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
         if (false === $raw && $this->protocol !== null) {
             /** @var ProtocolInterface $parser */
             $parser = $this->protocol;
-            $sendBuffer = $parser::encode($sendBuffer, $this);
+            try {
+                $sendBuffer = $parser::encode($sendBuffer, $this);
+            } catch(\Throwable $e) {
+                $this->error($e);
+            }
             if ($sendBuffer === '') {
                 return;
             }

+ 2 - 2
src/Events/Swoole.php

@@ -196,12 +196,12 @@ class Swoole implements EventInterface
     }
 
     /**
+     * Please see https://wiki.swoole.com/#/process/process?id=signal
      * {@inheritdoc}
      */
     public function offSignal(int $signal): bool
     {
-        return Process::signal($signal, function () {
-        });
+        return Process::signal($signal, null);
     }
 
     /**