@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | * @return int |
| 32 | 32 | * @throws SocketError |
| 33 | 33 | */ |
| 34 | - public static function select (array &$read, array &$write, array &$except, ?float $timeout = null): int { |
|
| 34 | + public static function select(array &$read, array &$write, array &$except, ?float $timeout = null): int { |
|
| 35 | 35 | $rwe = [$read, $write, $except]; |
| 36 | 36 | array_walk_recursive($rwe, function(SocketInterface &$each) { |
| 37 | 37 | $each = $each->getResource(); |
| 38 | 38 | }); |
| 39 | - $uSec = (int)(fmod($timeout, 1) * 1000000); // ignored if timeout is null |
|
| 39 | + $uSec = (int) (fmod($timeout, 1) * 1000000); // ignored if timeout is null |
|
| 40 | 40 | $count = @socket_select($rwe[0], $rwe[1], $rwe[2], $timeout, $uSec); // keys are preserved |
| 41 | 41 | if ($count === false) { |
| 42 | 42 | $read = $write = $except = []; |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param ReactiveInterface $socket |
| 55 | 55 | * @return $this |
| 56 | 56 | */ |
| 57 | - public function add (ReactiveInterface $socket) { |
|
| 57 | + public function add(ReactiveInterface $socket) { |
|
| 58 | 58 | $this->sockets[$socket->getId()] = $socket; |
| 59 | 59 | return $this; |
| 60 | 60 | } |
@@ -64,14 +64,14 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @return int |
| 66 | 66 | */ |
| 67 | - public function count (): int { |
|
| 67 | + public function count(): int { |
|
| 68 | 68 | return count($this->sockets); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * @return ReactiveInterface[] |
| 73 | 73 | */ |
| 74 | - public function getSockets () { |
|
| 74 | + public function getSockets() { |
|
| 75 | 75 | return $this->sockets; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @param ReactiveInterface $socket |
| 82 | 82 | * @return bool |
| 83 | 83 | */ |
| 84 | - public function has (ReactiveInterface $socket): bool { |
|
| 84 | + public function has(ReactiveInterface $socket): bool { |
|
| 85 | 85 | return isset($sockets[$socket->getId()]); |
| 86 | 86 | } |
| 87 | 87 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @param ReactiveInterface $socket |
| 91 | 91 | * @param Throwable $error |
| 92 | 92 | */ |
| 93 | - public function onError (int $channel, $socket, Throwable $error): void { |
|
| 93 | + public function onError(int $channel, $socket, Throwable $error): void { |
|
| 94 | 94 | unset($channel); |
| 95 | 95 | echo "{$error}\n\n"; |
| 96 | 96 | if ($socket->isOpen()) { |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @param float|null $timeout Maximum seconds to block. `NULL` blocks forever. |
| 114 | 114 | * @return int Number of sockets selected. |
| 115 | 115 | */ |
| 116 | - public function react (?float $timeout = null): int { |
|
| 116 | + public function react(?float $timeout = null): int { |
|
| 117 | 117 | /** @var ReactiveInterface[][] $rwe */ |
| 118 | 118 | $rwe = [$this->sockets, [], $this->sockets]; |
| 119 | 119 | $count = static::select($rwe[0], $rwe[1], $rwe[2], $timeout); |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @param ReactiveInterface $socket |
| 143 | 143 | * @return $this |
| 144 | 144 | */ |
| 145 | - public function remove (ReactiveInterface $socket) { |
|
| 145 | + public function remove(ReactiveInterface $socket) { |
|
| 146 | 146 | unset($this->sockets[$socket->getId()]); |
| 147 | 147 | return $this; |
| 148 | 148 | } |
@@ -96,8 +96,7 @@ discard block |
||
| 96 | 96 | if ($socket->isOpen()) { |
| 97 | 97 | if ($socket instanceof WebSocketClient and $error instanceof WebSocketError) { |
| 98 | 98 | $socket->close($error->getCode(), $error->getMessage()); |
| 99 | - } |
|
| 100 | - else { |
|
| 99 | + } else { |
|
| 101 | 100 | $socket->close(); |
| 102 | 101 | } |
| 103 | 102 | } |
@@ -121,12 +120,10 @@ discard block |
||
| 121 | 120 | foreach ($rwe[$channel] as $id => $socket) { |
| 122 | 121 | try { |
| 123 | 122 | $socket->{$method}(); |
| 124 | - } |
|
| 125 | - catch (Throwable $error) { |
|
| 123 | + } catch (Throwable $error) { |
|
| 126 | 124 | unset($rwe[0][$id]); // prevent onReadable() if this is an OOB error. |
| 127 | 125 | $this->onError($channel, $socket, $error); |
| 128 | - } |
|
| 129 | - finally { |
|
| 126 | + } finally { |
|
| 130 | 127 | if (!$socket->isOpen() and $this->has($socket)) { |
| 131 | 128 | $this->remove($socket); |
| 132 | 129 | } |