walkor 2 年之前
父节点
当前提交
41a46d7530
共有 3 个文件被更改,包括 61 次插入15 次删除
  1. 3 15
      src/Connection/ConnectionInterface.php
  2. 29 0
      src/Connection/TcpConnection.php
  3. 29 0
      src/Connection/UdpConnection.php

+ 3 - 15
src/Connection/ConnectionInterface.php

@@ -83,7 +83,7 @@ abstract class ConnectionInterface
     /**
      * @var ?EventInterface
      */
-    public ?EventInterface $eventLoop;
+    public ?EventInterface $eventLoop = null;
 
     /**
      * @var ?callable
@@ -154,26 +154,14 @@ abstract class ConnectionInterface
      *
      * return bool.
      */
-    public function isIpV4(): bool
-    {
-        if ($this->transport === 'unix') {
-            return false;
-        }
-        return !str_contains($this->getRemoteIp(), ':');
-    }
+    abstract public function isIpV4(): bool;
 
     /**
      * Is ipv6.
      *
      * return bool.
      */
-    public function isIpV6(): bool
-    {
-        if ($this->transport === 'unix') {
-            return false;
-        }
-        return str_contains($this->getRemoteIp(), ':');
-    }
+    abstract public function isIpV6(): bool;
 
     /**
      * @param Throwable $exception

+ 29 - 0
src/Connection/TcpConnection.php

@@ -14,6 +14,7 @@
 
 namespace Workerman\Connection;
 
+use JetBrains\PhpStorm\Pure;
 use JsonSerializable;
 use stdClass;
 use Throwable;
@@ -892,6 +893,34 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
     }
 
     /**
+     * Is ipv4.
+     *
+     * return bool.
+     */
+    #[Pure]
+    public function isIpV4(): bool
+    {
+        if ($this->transport === 'unix') {
+            return false;
+        }
+        return !str_contains($this->getRemoteIp(), ':');
+    }
+
+    /**
+     * Is ipv6.
+     *
+     * return bool.
+     */
+    #[Pure]
+    public function isIpV6(): bool
+    {
+        if ($this->transport === 'unix') {
+            return false;
+        }
+        return str_contains($this->getRemoteIp(), ':');
+    }
+
+    /**
      * Get the real socket.
      *
      * @return resource

+ 29 - 0
src/Connection/UdpConnection.php

@@ -15,6 +15,7 @@
 namespace Workerman\Connection;
 
 use JetBrains\PhpStorm\ArrayShape;
+use JetBrains\PhpStorm\Pure;
 use JsonSerializable;
 use Workerman\Protocols\ProtocolInterface;
 use function stream_socket_get_name;
@@ -176,6 +177,34 @@ class UdpConnection extends ConnectionInterface implements JsonSerializable
     }
 
     /**
+     * Is ipv4.
+     *
+     * return bool.
+     */
+    #[Pure]
+    public function isIpV4(): bool
+    {
+        if ($this->transport === 'unix') {
+            return false;
+        }
+        return !str_contains($this->getRemoteIp(), ':');
+    }
+
+    /**
+     * Is ipv6.
+     *
+     * return bool.
+     */
+    #[Pure]
+    public function isIpV6(): bool
+    {
+        if ($this->transport === 'unix') {
+            return false;
+        }
+        return str_contains($this->getRemoteIp(), ':');
+    }
+
+    /**
      * Get the real socket.
      *
      * @return resource