diff --git a/output/swoole/constants.php b/output/swoole/constants.php index 17160b0c..6470a27a 100644 --- a/output/swoole/constants.php +++ b/output/swoole/constants.php @@ -1,11 +1,11 @@ exists($key)) { + throw new ArrayKeyNotExists($key); + } return static::detectType($this->array[$key]); } @@ -314,6 +318,12 @@ public function pushFront($value) return array_unshift($this->array, $value); } + public function append(...$values): ArrayObject + { + array_push($this->array, ...$values); + return $this; + } + /** * @param mixed $value * @return int diff --git a/output/swoole_library/src/core/Constant.php b/output/swoole_library/src/core/Constant.php index fc35c82f..252667d5 100644 --- a/output/swoole_library/src/core/Constant.php +++ b/output/swoole_library/src/core/Constant.php @@ -72,16 +72,28 @@ class Constant public const OPTION_DNS_SERVER = 'dns_server'; + public const OPTION_SOCKET_DNS_TIMEOUT = 'socket_dns_timeout'; + + public const OPTION_SOCKET_CONNECT_TIMEOUT = 'socket_connect_timeout'; + + public const OPTION_SOCKET_WRITE_TIMEOUT = 'socket_write_timeout'; + public const OPTION_SOCKET_SEND_TIMEOUT = 'socket_send_timeout'; + public const OPTION_SOCKET_READ_TIMEOUT = 'socket_read_timeout'; + + public const OPTION_SOCKET_RECV_TIMEOUT = 'socket_recv_timeout'; + + public const OPTION_SOCKET_BUFFER_SIZE = 'socket_buffer_size'; + + public const OPTION_SOCKET_TIMEOUT = 'socket_timeout'; + public const OPTION_ENABLE_SIGNALFD = 'enable_signalfd'; public const OPTION_WAIT_SIGNAL = 'wait_signal'; public const OPTION_DNS_CACHE_REFRESH_TIME = 'dns_cache_refresh_time'; - public const OPTION_SOCKET_BUFFER_SIZE = 'socket_buffer_size'; - public const OPTION_THREAD_NUM = 'thread_num'; public const OPTION_MIN_THREAD_NUM = 'min_thread_num'; @@ -188,16 +200,6 @@ class Constant public const OPTION_STACK_SIZE = 'stack_size'; - public const OPTION_SOCKET_DNS_TIMEOUT = 'socket_dns_timeout'; - - public const OPTION_SOCKET_CONNECT_TIMEOUT = 'socket_connect_timeout'; - - public const OPTION_SOCKET_TIMEOUT = 'socket_timeout'; - - public const OPTION_SOCKET_READ_TIMEOUT = 'socket_read_timeout'; - - public const OPTION_SOCKET_WRITE_TIMEOUT = 'socket_write_timeout'; - public const OPTION_DNS_CACHE_EXPIRE = 'dns_cache_expire'; public const OPTION_DNS_CACHE_CAPACITY = 'dns_cache_capacity'; @@ -214,6 +216,8 @@ class Constant public const OPTION_DEFER = 'defer'; + public const OPTION_LOWERCASE_HEADER = 'lowercase_header'; + public const OPTION_KEEP_ALIVE = 'keep_alive'; public const OPTION_WEBSOCKET_MASK = 'websocket_mask'; @@ -372,6 +376,8 @@ class Constant public const OPTION_TCP_KEEPCOUNT = 'tcp_keepcount'; + public const OPTION_TCP_USER_TIMEOUT = 'tcp_user_timeout'; + public const OPTION_TCP_FASTOPEN = 'tcp_fastopen'; public const OPTION_PACKAGE_BODY_START = 'package_body_start'; diff --git a/output/swoole_library/src/core/Coroutine/Barrier.php b/output/swoole_library/src/core/Coroutine/Barrier.php new file mode 100644 index 00000000..2e8f099e --- /dev/null +++ b/output/swoole_library/src/core/Coroutine/Barrier.php @@ -0,0 +1,64 @@ +timer != -1) { + Timer::clear($this->timer); + if (static::$cancel_list[$this->cid]) { + unset(static::$cancel_list[$this->cid]); + return; + } + } + if ($this->cid != -1) { + Coroutine::resume($this->cid); + } + } + + public static function make() + { + return new static(); + } + + /** + * @throws Exception + */ + public static function wait(Barrier &$barrier, float $timeout = -1) + { + if ($barrier->cid != -1) { + throw new Exception('The barrier is waiting, cannot wait again.'); + } + $cid = Coroutine::getCid(); + $barrier->cid = $cid; + if ($timeout > 0 && ($timeout_ms = intval($timeout * 1000)) > 0) { + $barrier->timer = Timer::after($timeout_ms, function () use ($cid) { + self::$cancel_list[$cid] = true; + Coroutine::resume($cid); + }); + } + $barrier = null; + Coroutine::yield(); + } +} diff --git a/output/swoole_library/src/core/Coroutine/WaitGroup.php b/output/swoole_library/src/core/Coroutine/WaitGroup.php index dc2bfe10..f2b6a02c 100644 --- a/output/swoole_library/src/core/Coroutine/WaitGroup.php +++ b/output/swoole_library/src/core/Coroutine/WaitGroup.php @@ -22,9 +22,12 @@ class WaitGroup protected $waiting = false; - public function __construct() + public function __construct(int $delta = 0) { $this->chan = new Channel(1); + if ($delta > 0) { + $this->add($delta); + } } public function add(int $delta = 1): void diff --git a/output/swoole_library/src/core/Coroutine/functions.php b/output/swoole_library/src/core/Coroutine/functions.php index 40dcae38..a9a0cc37 100644 --- a/output/swoole_library/src/core/Coroutine/functions.php +++ b/output/swoole_library/src/core/Coroutine/functions.php @@ -27,3 +27,17 @@ function batch(array $tasks, float $timeout = -1): array $wg->wait($timeout); return $tasks; } + +function parallel(int $n, callable $fn): void +{ + $count = $n; + $wg = new WaitGroup(); + $wg->add($n); + while ($count--) { + Coroutine::create(function () use ($fn, $wg) { + $fn(); + $wg->done(); + }); + } + $wg->wait(); +} diff --git a/output/swoole_library/src/core/Curl/Handler.php b/output/swoole_library/src/core/Curl/Handler.php index ecd40b35..eff8406e 100644 --- a/output/swoole_library/src/core/Curl/Handler.php +++ b/output/swoole_library/src/core/Curl/Handler.php @@ -496,10 +496,15 @@ private function setOption(int $opt, $value): bool $this->method = (string) $value; break; case CURLOPT_PROTOCOLS: - if ($value > 3) { + if (($value & ~(CURLPROTO_HTTP | CURLPROTO_HTTPS)) != 0) { throw new CurlException("swoole_curl_setopt(): CURLOPT_PROTOCOLS[{$value}] is not supported"); } break; + case CURLOPT_REDIR_PROTOCOLS: + if (($value & ~(CURLPROTO_HTTP | CURLPROTO_HTTPS)) != 0) { + throw new CurlException("swoole_curl_setopt(): CURLOPT_REDIR_PROTOCOLS[{$value}] is not supported"); + } + break; case CURLOPT_HTTP_VERSION: if ($value != CURL_HTTP_VERSION_1_1) { trigger_error("swoole_curl_setopt(): CURLOPT_HTTP_VERSION[{$value}] is not supported", E_USER_WARNING); @@ -710,6 +715,8 @@ private function execute() $errCode = $client->errCode; if ($errCode == SWOOLE_ERROR_DNSLOOKUP_RESOLVE_FAILED or $errCode == SWOOLE_ERROR_DNSLOOKUP_RESOLVE_TIMEOUT) { $this->setError(CURLE_COULDNT_RESOLVE_HOST, 'Could not resolve host: ' . $client->host); + } else { + $this->setError($errCode, $client->errMsg); } $this->info['total_time'] = microtime(true) - $timeBegin; return false; diff --git a/output/swoole_library/src/core/Database/MysqliPool.php b/output/swoole_library/src/core/Database/MysqliPool.php index 70d3bde2..c63b34e9 100644 --- a/output/swoole_library/src/core/Database/MysqliPool.php +++ b/output/swoole_library/src/core/Database/MysqliPool.php @@ -40,7 +40,7 @@ public function __construct(MysqliConfig $config, int $size = self::DEFAULT_SIZE $this->config->getUnixSocket() ); if ($mysqli->connect_errno) { - throw new MysqliException($mysqli->connect_errno, $mysqli->connect_errno); + throw new MysqliException($mysqli->connect_error, $mysqli->connect_errno); } return $mysqli; }, $size, MysqliProxy::class); diff --git a/output/swoole_library/src/core/Exception/ArrayKeyNotExists.php b/output/swoole_library/src/core/Exception/ArrayKeyNotExists.php new file mode 100644 index 00000000..95b2a588 --- /dev/null +++ b/output/swoole_library/src/core/Exception/ArrayKeyNotExists.php @@ -0,0 +1,16 @@ +string, $needle) === 0; } - public function contains(string $subString): bool + public function endsWith(string $needle): bool { - return strpos($this->string, $subString) !== false; + return strrpos($this->string, $needle) === (strlen($this->string) - strlen($needle)); } - public function endsWith(string $needle): bool + public function equals($str, bool $strict = false): bool { - return strrpos($this->string, $needle) === (strlen($this->string) - strlen($needle)); + if ($str instanceof StringObject) { + $str = strval($str); + } + if ($strict) { + return $this->string === $str; + } + return $this->string == $str; + } + + public function contains(string $subString): bool + { + return strpos($this->string, $subString) !== false; } public function split(string $delimiter, int $limit = PHP_INT_MAX): ArrayObject