Skip to content

Commit

Permalink
updates for Swoole 4.4.21
Browse files Browse the repository at this point in the history
  • Loading branch information
deminy committed Sep 22, 2020
1 parent 332adf9 commit 9bbac77
Show file tree
Hide file tree
Showing 13 changed files with 373 additions and 67 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.4.20');
define('SWOOLE_VERSION_ID', 40420);
define('SWOOLE_VERSION', '4.4.21');
define('SWOOLE_VERSION_ID', 40421);
define('SWOOLE_MAJOR_VERSION', 4);
define('SWOOLE_MINOR_VERSION', 4);
define('SWOOLE_RELEASE_VERSION', 20);
define('SWOOLE_RELEASE_VERSION', 21);
define('SWOOLE_EXTRA_VERSION', '');
define('SWOOLE_DEBUG', '');
define('SWOOLE_HAVE_COMPRESSION', '1');
Expand Down
118 changes: 90 additions & 28 deletions output/swoole_library/src/core/ArrayObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Iterator;
use RuntimeException;
use Serializable;
use Swoole\Exception\ArrayKeyNotExists;

class ArrayObject implements ArrayAccess, Serializable, Countable, Iterator
{
Expand All @@ -37,6 +38,11 @@ public function __toArray(): array
return $this->array;
}

public function toArray(): array
{
return $this->array;
}

public function isEmpty(): bool
{
return empty($this->array);
Expand Down Expand Up @@ -90,9 +96,52 @@ public function next()
*/
public function get($key)
{
if (!$this->exists($key)) {
throw new ArrayKeyNotExists($key);
}
return static::detectType($this->array[$key]);
}

/**
* @return mixed
*/
public function last()
{
$key = array_key_last($this->array);
if ($key === null) {
return null;
}
return $this->get($key);
}

/**
* @return null|int|string
*/
public function firstKey()
{
return array_key_first($this->array);
}

/**
* @return null|int|string
*/
public function lastKey()
{
return array_key_last($this->array);
}

/**
* @return mixed
*/
public function first()
{
$key = array_key_first($this->array);
if ($key === null) {
return null;
}
return $this->get($key);
}

/**
* @param mixed $key
* @param mixed $value
Expand Down Expand Up @@ -122,12 +171,12 @@ public function remove($value, bool $strict = true, bool $loop = false): self
{
do {
$key = $this->search($value, $strict);
if ($key) {
unset($this->array[$key]);
} else {
if ($key === false) {
break;
}
unset($this->array[$key]);
} while ($loop);

return $this;
}

Expand Down Expand Up @@ -273,18 +322,33 @@ public function product()
*/
public function push($value)
{
return array_push($this->array, $value);
return $this->pushBack($value);
}

/**
* @param mixed $value
* @return int
*/
public function pushBack($value)
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
*/
public function pushBack($value)
{
return array_push($this->array, $value);
}

/**
* @param mixed $value
* @return $this
Expand All @@ -303,7 +367,7 @@ public function insert(int $offset, $value): self
*/
public function pop()
{
return array_pop($this->array);
return $this->popBack();
}

/**
Expand All @@ -314,6 +378,14 @@ public function popFront()
return array_shift($this->array);
}

/**
* @return mixed
*/
public function popBack()
{
return array_pop($this->array);
}

/**
* @param mixed $offset
* @param int $length
Expand Down Expand Up @@ -344,29 +416,30 @@ public function each(callable $fn): self
}

/**
* @param array $args
* @return static
*/
public function map(callable $fn): self
public function map(callable $fn, ...$args): self
{
return new static(array_map($fn, $this->array));
return new static(array_map($fn, $this->array, ...$args));
}

/**
* @param null $initial
* @return mixed
*/
public function reduce(callable $fn)
public function reduce(callable $fn, $initial = null)
{
return array_reduce($this->array, $fn);
return array_reduce($this->array, $fn, $initial);
}

/**
* @param int $search_value
* @param bool $strict
* @param array $args
* @return static
*/
public function keys(int $search_value = null, $strict = false): self
public function keys(...$args): self
{
return new static(array_keys($this->array, $search_value, $strict));
return new static(array_keys($this->array, ...$args));
}

/**
Expand All @@ -379,12 +452,12 @@ public function values(): self

/**
* @param mixed $column_key
* @param mixed ...$index
* @param mixed $index
* @return static
*/
public function column($column_key, ...$index): self
public function column($column_key, $index = null): self
{
return new static(array_column($this->array, $column_key, ...$index));
return new static(array_column($this->array, $column_key, $index));
}

/**
Expand Down Expand Up @@ -446,17 +519,6 @@ public function filter(callable $fn, int $flag = 0): self
* | usort() | value | no | user defined | uasort() |
*/

/**
* @return $this
*/
public function multiSort(int $sort_order = SORT_ASC, int $sort_flags = SORT_REGULAR): self
{
if (array_multisort($this->array, $sort_order, $sort_flags) !== true) {
throw new RuntimeException('array_multisort() failed');
}
return $this;
}

/**
* @return $this
*/
Expand Down
34 changes: 22 additions & 12 deletions output/swoole_library/src/core/Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,34 @@ class Constant

public const OPTION_LOG_DATE_WITH_MICROSECONDS = 'log_date_with_microseconds';

public const OPTION_LOG_ROTATION = 'log_rotation';

public const OPTION_DISPLAY_ERRORS = 'display_errors';

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_ENABLE_SIGNALFD = 'enable_signalfd';
public const OPTION_SOCKET_READ_TIMEOUT = 'socket_read_timeout';

public const OPTION_DNS_CACHE_REFRESH_TIME = 'dns_cache_refresh_time';
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_THREAD_NUM = 'thread_num';

public const OPTION_MIN_THREAD_NUM = 'min_thread_num';
Expand Down Expand Up @@ -184,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';
Expand All @@ -210,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';
Expand Down Expand Up @@ -368,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';
Expand Down
64 changes: 64 additions & 0 deletions output/swoole_library/src/core/Coroutine/Barrier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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;

use Swoole\Coroutine;
use Swoole\Exception;
use Swoole\Timer;

class Barrier
{
private $cid = -1;

private $timer = -1;

private static $cancel_list = [];

public function __destruct()
{
if ($this->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();
}
}
5 changes: 4 additions & 1 deletion output/swoole_library/src/core/Coroutine/WaitGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 9bbac77

Please sign in to comment.