File tree Expand file tree Collapse file tree 1 file changed +14
-9
lines changed
Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -19,15 +19,20 @@ class AsyncSocket
1919 private int $ type ;
2020 private float $ timeout ;
2121
22- public const TYPE_TCP = \SWOOLE_SOCK_TCP ;
23- public const TYPE_UDP = \SWOOLE_SOCK_UDP ;
24- public const TYPE_TCP6 = \SWOOLE_SOCK_TCP6 ;
25- public const TYPE_UDP6 = \SWOOLE_SOCK_UDP6 ;
26- public const TYPE_UNIX_STREAM = \SWOOLE_SOCK_UNIX_STREAM ;
27- public const TYPE_UNIX_DGRAM = \SWOOLE_SOCK_UNIX_DGRAM ;
28-
29- public function __construct (int $ type = self ::TYPE_TCP , float $ timeout = 5.0 )
30- {
22+ // Constants defined conditionally to avoid errors when Swoole is not loaded
23+ public const TYPE_TCP = 1 ; // SWOOLE_SOCK_TCP
24+ public const TYPE_UDP = 2 ; // SWOOLE_SOCK_UDP
25+ public const TYPE_TCP6 = 3 ; // SWOOLE_SOCK_TCP6
26+ public const TYPE_UDP6 = 4 ; // SWOOLE_SOCK_UDP6
27+ public const TYPE_UNIX_STREAM = 5 ; // SWOOLE_SOCK_UNIX_STREAM
28+ public const TYPE_UNIX_DGRAM = 6 ; // SWOOLE_SOCK_UNIX_DGRAM
29+
30+ public function __construct (?int $ type = null , float $ timeout = 5.0 )
31+ {
32+ // Use Swoole constants if available, otherwise use our fallback values
33+ if ($ type === null ) {
34+ $ type = \defined ('SWOOLE_SOCK_TCP ' ) ? \SWOOLE_SOCK_TCP : self ::TYPE_TCP ;
35+ }
3136 $ this ->type = $ type ;
3237 $ this ->timeout = $ timeout ;
3338 }
You can’t perform that action at this time.
0 commit comments