Skip to content

Commit

Permalink
updates for Swoole 4.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
deminy committed Mar 11, 2021
1 parent 3292fef commit 7e5c51c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 18 deletions.
6 changes: 3 additions & 3 deletions output/swoole/constants.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

define('SWOOLE_VERSION', '4.6.3');
define('SWOOLE_VERSION_ID', 40603);
define('SWOOLE_VERSION', '4.6.4');
define('SWOOLE_VERSION_ID', 40604);
define('SWOOLE_MAJOR_VERSION', 4);
define('SWOOLE_MINOR_VERSION', 6);
define('SWOOLE_RELEASE_VERSION', 3);
define('SWOOLE_RELEASE_VERSION', 4);
define('SWOOLE_EXTRA_VERSION', '');
define('SWOOLE_DEBUG', '');
define('SWOOLE_HAVE_COMPRESSION', '1');
Expand Down
7 changes: 0 additions & 7 deletions output/swoole/namespace/Redis/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ class Server extends \Swoole\Server

public const MAP = 6;

/**
* @return mixed
*/
public function start()
{
}

/**
* @return mixed
*/
Expand Down
16 changes: 9 additions & 7 deletions output/swoole_library/src/core/Coroutine/Barrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ class Barrier

public function __destruct()
{
if ($this->timer != -1) {
if ($this->timer !== -1) {
Timer::clear($this->timer);
if (isset(static::$cancel_list[$this->cid])) {
unset(static::$cancel_list[$this->cid]);
if (isset(self::$cancel_list[$this->cid])) {
unset(self::$cancel_list[$this->cid]);
return;
}
}
if ($this->cid != -1 && $this->cid != Coroutine::getCid()) {
if ($this->cid !== -1 && $this->cid !== Coroutine::getCid()) {
Coroutine::resume($this->cid);
} else {
static::$cancel_list[$this->cid] = true;
self::$cancel_list[$this->cid] = true;
}
}

Expand All @@ -49,12 +49,12 @@ public static function make()
*/
public static function wait(Barrier &$barrier, float $timeout = -1)
{
if ($barrier->cid != -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) {
if ($timeout > 0 && ($timeout_ms = (int) ($timeout * 1000)) > 0) {
$barrier->timer = Timer::after($timeout_ms, function () use ($cid) {
self::$cancel_list[$cid] = true;
Coroutine::resume($cid);
Expand All @@ -63,6 +63,8 @@ public static function wait(Barrier &$barrier, float $timeout = -1)
$barrier = null;
if (!isset(self::$cancel_list[$cid])) {
Coroutine::yield();
} else {
unset(self::$cancel_list[$cid]);
}
}
}
71 changes: 71 additions & 0 deletions output/swoole_library/src/core/Coroutine/Http/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* This file is part of Swoole.
*
* @link https://www.swoole.com
* @contact [email protected]
* @license https://github.com/swoole/library/blob/master/LICENSE
*/

declare(strict_types=1);

namespace Swoole\Coroutine\Http;

use Swoole\Coroutine\Http\Client\Exception;

/**
* @param mixed $data
* @throws Exception
* @return mixed
*/
function request(string $url, string $method, $data = null, array $options = null, array $headers = null, array $cookies = null)
{
$info = parse_url($url);
if ($info['scheme'] == 'http') {
$client = new Client($info['host'], swoole_array_default_value($info, 'port', 80), false);
} elseif ($info['scheme'] == 'https') {
$client = new Client($info['host'], swoole_array_default_value($info, 'port', 443), true);
} else {
throw new Exception('unknown scheme "' . $info['scheme'] . '"');
}
$client->setMethod($method);
if ($data) {
$client->setData($data);
}
if (is_array($options)) {
$client->set($options);
}
if (is_array($headers)) {
$client->setHeaders($options);
}
if (is_array($cookies)) {
$client->setCookies($options);
}
$request_url = swoole_array_default_value($info, 'path', '/');
if (!empty($info['query'])) {
$request_url .= '?' . $info['query'];
}
if ($client->execute($request_url)) {
return $client;
}
return false;
}

/**
* @param mixed $data
* @throws Exception
* @return Client|false|mixed
*/
function post(string $url, $data, array $options = null, array $headers = null, array $cookies = null)
{
return request($url, 'POST', $data, $options, $headers, $cookies);
}

/**
* @throws Exception
* @return Client|false|mixed
*/
function get(string $url, array $options = null, array $headers = null, array $cookies = null)
{
return request($url, 'GET', null, $options, $headers, $cookies);
}
2 changes: 1 addition & 1 deletion output/swoole_library/src/core/Curl/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private function setUrlInfo(array $urlInfo): bool
private function setPort(int $port): void
{
$this->info['primary_port'] = $port;
if ($this->urlInfo['port'] !== $port) {
if (!isset($this->urlInfo['port']) || $this->urlInfo['port'] !== $port) {
$this->urlInfo['port'] = $port;
if ($this->client) {
/* target changed */
Expand Down

0 comments on commit 7e5c51c

Please sign in to comment.