@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @return static |
| 42 | 42 | * @throws SocketError |
| 43 | 43 | */ |
| 44 | - public static function create ($domain = AF_INET, ...$extra) { |
|
| 44 | + public static function create($domain = AF_INET, ...$extra) { |
|
| 45 | 45 | if (!$resource = @socket_create($domain, static::getType(), 0)) { // auto-protocol |
| 46 | 46 | throw new SocketError; // reliable errno |
| 47 | 47 | } |
@@ -58,12 +58,12 @@ discard block |
||
| 58 | 58 | * @throws SocketError (`SOCKET_EBADFD`) There was a pending error on the socket. |
| 59 | 59 | * The preexisting error code is set as the exception's extra data. |
| 60 | 60 | */ |
| 61 | - public function __construct ($resource) { |
|
| 61 | + public function __construct($resource) { |
|
| 62 | 62 | if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') { |
| 63 | 63 | throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF); |
| 64 | 64 | } |
| 65 | 65 | elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) { |
| 66 | - throw new InvalidArgumentException('The given socket resource is of the wrong type for ' . get_class(), SOCKET_ESOCKTNOSUPPORT); |
|
| 66 | + throw new InvalidArgumentException('The given socket resource is of the wrong type for '.get_class(), SOCKET_ESOCKTNOSUPPORT); |
|
| 67 | 67 | } |
| 68 | 68 | elseif ($errno = SocketError::getLast($resource)) { |
| 69 | 69 | $error = new SocketError(SOCKET_EBADFD); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | /** |
| 79 | 79 | * Closes the socket if it's open. |
| 80 | 80 | */ |
| 81 | - public function __destruct () { |
|
| 81 | + public function __destruct() { |
|
| 82 | 82 | if ($this->isOpen()) { |
| 83 | 83 | $this->close(); |
| 84 | 84 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @return $this |
| 96 | 96 | * @throws SocketError |
| 97 | 97 | */ |
| 98 | - public function await ($channel) { |
|
| 98 | + public function await($channel) { |
|
| 99 | 99 | $rwe = [$channel => [$this->resource]]; |
| 100 | 100 | if (!@socket_select($rwe[0], $rwe[1], $rwe[2], null)) { |
| 101 | 101 | throw new SocketError($this->resource); |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @return $this |
| 110 | 110 | */ |
| 111 | - final public function awaitOutOfBand () { |
|
| 111 | + final public function awaitOutOfBand() { |
|
| 112 | 112 | return $this->await(self::CH_EXCEPT); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @return $this |
| 119 | 119 | */ |
| 120 | - final public function awaitReadable () { |
|
| 120 | + final public function awaitReadable() { |
|
| 121 | 121 | return $this->await(self::CH_READ); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @return $this |
| 128 | 128 | */ |
| 129 | - final public function awaitWritable () { |
|
| 129 | + final public function awaitWritable() { |
|
| 130 | 130 | return $this->await(self::CH_WRITE); |
| 131 | 131 | } |
| 132 | 132 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | * @return $this |
| 139 | 139 | */ |
| 140 | - public function close () { |
|
| 140 | + public function close() { |
|
| 141 | 141 | socket_close($this->resource); // never errors |
| 142 | 142 | return $this; |
| 143 | 143 | } |
@@ -145,14 +145,14 @@ discard block |
||
| 145 | 145 | /** |
| 146 | 146 | * @return int |
| 147 | 147 | */ |
| 148 | - final public function getDomain (): int { |
|
| 148 | + final public function getDomain(): int { |
|
| 149 | 149 | return $this->domain; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
| 153 | 153 | * @return int |
| 154 | 154 | */ |
| 155 | - final public function getId (): int { |
|
| 155 | + final public function getId(): int { |
|
| 156 | 156 | return (int)$this->resource; |
| 157 | 157 | } |
| 158 | 158 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @throws SocketError |
| 166 | 166 | * @return mixed The option's value. This is never `false`. |
| 167 | 167 | */ |
| 168 | - public function getOption ($option) { |
|
| 168 | + public function getOption($option) { |
|
| 169 | 169 | $value = @socket_get_option($this->resource, SOL_SOCKET, $option); |
| 170 | 170 | if ($value === false) { |
| 171 | 171 | throw new SocketError($this->resource, SOCKET_EINVAL); |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | /** |
| 177 | 177 | * @return int |
| 178 | 178 | */ |
| 179 | - final public function getProtocol (): int { |
|
| 179 | + final public function getProtocol(): int { |
|
| 180 | 180 | return $this->protocol; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
| 184 | 184 | * @return resource |
| 185 | 185 | */ |
| 186 | - final public function getResource () { |
|
| 186 | + final public function getResource() { |
|
| 187 | 187 | return $this->resource; |
| 188 | 188 | } |
| 189 | 189 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * @throws SocketError |
| 196 | 196 | * @return array String address/file and integer port at indices `0` and `1`. |
| 197 | 197 | */ |
| 198 | - public function getSockName () { |
|
| 198 | + public function getSockName() { |
|
| 199 | 199 | if (!@socket_getsockname($this->resource, $addr, $port)) { |
| 200 | 200 | throw new SocketError($this->resource, SOCKET_EOPNOTSUPP); |
| 201 | 201 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | * |
| 208 | 208 | * @return bool |
| 209 | 209 | */ |
| 210 | - public function isOpen (): bool { |
|
| 210 | + public function isOpen(): bool { |
|
| 211 | 211 | return is_resource($this->resource); |
| 212 | 212 | } |
| 213 | 213 | |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * @return bool |
| 220 | 220 | * @throws SocketError |
| 221 | 221 | */ |
| 222 | - public function isOutOfBand () { |
|
| 222 | + public function isOutOfBand() { |
|
| 223 | 223 | return $this->isReady(self::CH_EXCEPT); |
| 224 | 224 | } |
| 225 | 225 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | * @return bool |
| 232 | 232 | * @throws SocketError |
| 233 | 233 | */ |
| 234 | - final public function isReadable () { |
|
| 234 | + final public function isReadable() { |
|
| 235 | 235 | return $this->isReady(self::CH_READ); |
| 236 | 236 | } |
| 237 | 237 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | * @return bool |
| 246 | 246 | * @throws SocketError |
| 247 | 247 | */ |
| 248 | - public function isReady ($channel, $timeout = 0.0): bool { |
|
| 248 | + public function isReady($channel, $timeout = 0.0): bool { |
|
| 249 | 249 | $rwe = [$channel => [$this->resource]]; |
| 250 | 250 | // core casts non-null timeout to int. |
| 251 | 251 | // usec is ignored if timeout is null. |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * @return bool |
| 265 | 265 | * @throws SocketError |
| 266 | 266 | */ |
| 267 | - final public function isWritable () { |
|
| 267 | + final public function isWritable() { |
|
| 268 | 268 | return $this->isReady(self::CH_WRITE); |
| 269 | 269 | } |
| 270 | 270 | |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | * @throws SocketError |
| 287 | 287 | * @return $this |
| 288 | 288 | */ |
| 289 | - public function setBlocking ($blocking) { |
|
| 289 | + public function setBlocking($blocking) { |
|
| 290 | 290 | if ($blocking) { |
| 291 | 291 | $success = @socket_set_block($this->resource); |
| 292 | 292 | } |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * @throws SocketError |
| 310 | 310 | * @return $this |
| 311 | 311 | */ |
| 312 | - public function setOption ($option, $value) { |
|
| 312 | + public function setOption($option, $value) { |
|
| 313 | 313 | if (!@socket_set_option($this->resource, SOL_SOCKET, $option, $value)) { |
| 314 | 314 | throw new SocketError($this->resource, SOCKET_EINVAL); |
| 315 | 315 | } |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | * @return $this |
| 324 | 324 | * @throws SocketError |
| 325 | 325 | */ |
| 326 | - public function setTimeout ($timeout) { |
|
| 326 | + public function setTimeout($timeout) { |
|
| 327 | 327 | $tv = [ |
| 328 | 328 | 'sec' => (int)$timeout, |
| 329 | 329 | 'usec' => (int)(fmod($timeout, 1) * 1000000) |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | * @throws SocketError |
| 357 | 357 | * @return $this |
| 358 | 358 | */ |
| 359 | - public function shutdown (int $channels = self::CH_READ | self::CH_WRITE) { |
|
| 359 | + public function shutdown(int $channels = self::CH_READ | self::CH_WRITE) { |
|
| 360 | 360 | if (!@socket_shutdown($this->resource, $channels)) { |
| 361 | 361 | throw new SocketError($this->resource); // reliable errno |
| 362 | 362 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * |
| 13 | 13 | * @return int |
| 14 | 14 | */ |
| 15 | - final public static function getType (): int { |
|
| 15 | + final public static function getType(): int { |
|
| 16 | 16 | return SOCK_STREAM; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * @return static[] Two instances at indices `0` and `1`. |
| 27 | 27 | * @throws SocketError |
| 28 | 28 | */ |
| 29 | - public static function newUnixPair (...$extra) { |
|
| 29 | + public static function newUnixPair(...$extra) { |
|
| 30 | 30 | if (!@socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $fd)) { |
| 31 | 31 | throw new SocketError; // reliable errno |
| 32 | 32 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @return string |
| 46 | 46 | * @throws SocketError The error's extra data is set to what was partially read. |
| 47 | 47 | */ |
| 48 | - public function read ($length) { |
|
| 48 | + public function read($length) { |
|
| 49 | 49 | try { |
| 50 | 50 | $data = ''; |
| 51 | 51 | do { |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @throws SocketError |
| 71 | 71 | * @return string |
| 72 | 72 | */ |
| 73 | - public function recv ($length, $msgFlags = 0): string { |
|
| 73 | + public function recv($length, $msgFlags = 0): string { |
|
| 74 | 74 | if (false === @socket_recv($this->resource, $data, $length, $msgFlags)) { |
| 75 | 75 | throw new SocketError($this->resource, SOCKET_EINVAL); |
| 76 | 76 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @param int $msgFlags |
| 86 | 86 | * @return string |
| 87 | 87 | */ |
| 88 | - public function recvAll (int $msgFlags = 0): string { |
|
| 88 | + public function recvAll(int $msgFlags = 0): string { |
|
| 89 | 89 | $msgFlags = ($msgFlags & ~MSG_WAITALL) | MSG_DONTWAIT; |
| 90 | 90 | $length = $this->getOption(SO_RCVBUF); |
| 91 | 91 | try { |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @return int |
| 29 | 29 | * @throws SocketError |
| 30 | 30 | */ |
| 31 | - public static function select (array &$read, array &$write, array &$except, $timeout = null) { |
|
| 31 | + public static function select(array &$read, array &$write, array &$except, $timeout = null) { |
|
| 32 | 32 | $rwe = [$read, $write, $except]; |
| 33 | 33 | array_walk_recursive($rwe, function(SocketInterface &$each) { |
| 34 | 34 | $each = $each->getResource(); |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param ReactiveInterface $socket |
| 52 | 52 | * @return $this |
| 53 | 53 | */ |
| 54 | - public function add (ReactiveInterface $socket) { |
|
| 54 | + public function add(ReactiveInterface $socket) { |
|
| 55 | 55 | $this->sockets[$socket->getId()] = $socket; |
| 56 | 56 | return $this; |
| 57 | 57 | } |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return int |
| 63 | 63 | */ |
| 64 | - public function count () { |
|
| 64 | + public function count() { |
|
| 65 | 65 | return count($this->sockets); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * @return SocketInterface[] |
| 70 | 70 | */ |
| 71 | - public function getSockets () { |
|
| 71 | + public function getSockets() { |
|
| 72 | 72 | return $this->sockets; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @param float|null $timeout Maximum seconds to block. `NULL` blocks forever. |
| 83 | 83 | * @return int Number of sockets selected. |
| 84 | 84 | */ |
| 85 | - public function react ($timeout = null) { |
|
| 85 | + public function react($timeout = null) { |
|
| 86 | 86 | /** @var ReactiveInterface[][] $rwe */ |
| 87 | 87 | $rwe = [$this->sockets, [], $this->sockets]; |
| 88 | 88 | $count = static::select($rwe[0], $rwe[1], $rwe[2], $timeout); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param int|ReactiveInterface $id |
| 111 | 111 | * @return $this |
| 112 | 112 | */ |
| 113 | - public function remove ($id) { |
|
| 113 | + public function remove($id) { |
|
| 114 | 114 | unset($this->sockets[$id instanceof ReactiveInterface ? $id->getId() : $id]); |
| 115 | 115 | return $this; |
| 116 | 116 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * @param resource $resource PHP socket resource, or `null` for the global error. |
| 28 | 28 | * @return int If the resource is closed or not a socket, `SOCKET_EBADF` is returned. |
| 29 | 29 | */ |
| 30 | - public static function getLast ($resource = null) { |
|
| 30 | + public static function getLast($resource = null) { |
|
| 31 | 31 | if (isset($resource)) { |
| 32 | 32 | if (@get_resource_type($resource) !== 'Socket') { |
| 33 | 33 | return SOCKET_EBADF; |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * PHP's last suppressed warning is used for the message. |
| 54 | 54 | * |
| 55 | 55 | */ |
| 56 | - public function __construct ($subject = null, $fallback = 0) { |
|
| 56 | + public function __construct($subject = null, $fallback = 0) { |
|
| 57 | 57 | if (is_int($subject)) { |
| 58 | 58 | $errno = $subject; |
| 59 | 59 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | /** |
| 74 | 74 | * @return mixed |
| 75 | 75 | */ |
| 76 | - public function getExtra () { |
|
| 76 | + public function getExtra() { |
|
| 77 | 77 | return $this->extra; |
| 78 | 78 | } |
| 79 | 79 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @param mixed $extra |
| 82 | 82 | * @return $this |
| 83 | 83 | */ |
| 84 | - public function setExtra ($extra) { |
|
| 84 | + public function setExtra($extra) { |
|
| 85 | 85 | $this->extra = $extra; |
| 86 | 86 | return $this; |
| 87 | 87 | } |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | * |
| 13 | 13 | * @return int |
| 14 | 14 | */ |
| 15 | - final public static function getType (): int { |
|
| 15 | + final public static function getType(): int { |
|
| 16 | 16 | return SOCK_DGRAM; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @return string |
| 18 | 18 | */ |
| 19 | - public function __toString () { |
|
| 19 | + public function __toString() { |
|
| 20 | 20 | try { |
| 21 | 21 | return implode(':', $this->getSockName()); |
| 22 | 22 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @throws SocketError |
| 39 | 39 | * @return $this |
| 40 | 40 | */ |
| 41 | - public function bind (string $address, int $port = 0) { |
|
| 41 | + public function bind(string $address, int $port = 0) { |
|
| 42 | 42 | if (!@socket_bind($this->resource, $address, $port)) { |
| 43 | 43 | throw new SocketError($this->resource, SOCKET_EOPNOTSUPP); |
| 44 | 44 | } |
@@ -42,41 +42,41 @@ |
||
| 42 | 42 | * |
| 43 | 43 | * @return int `SOCK_*` |
| 44 | 44 | */ |
| 45 | - public static function getType (): int; |
|
| 45 | + public static function getType(): int; |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * Returns the address family constant of the socket. |
| 49 | 49 | * |
| 50 | 50 | * @return int `AF_*` |
| 51 | 51 | */ |
| 52 | - public function getDomain (): int; |
|
| 52 | + public function getDomain(): int; |
|
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * Returns the underlying socket resource as an integer. |
| 56 | 56 | * |
| 57 | 57 | * @return int |
| 58 | 58 | */ |
| 59 | - public function getId (): int; |
|
| 59 | + public function getId(): int; |
|
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * Returns the protocol constant used by the socket. |
| 63 | 63 | * |
| 64 | 64 | * @return int |
| 65 | 65 | */ |
| 66 | - public function getProtocol (): int; |
|
| 66 | + public function getProtocol(): int; |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * Returns the underlying socket resource. |
| 70 | 70 | * |
| 71 | 71 | * @return resource |
| 72 | 72 | */ |
| 73 | - public function getResource (); |
|
| 73 | + public function getResource(); |
|
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * Whether the underlying resource is usable. |
| 77 | 77 | * |
| 78 | 78 | * @return bool |
| 79 | 79 | */ |
| 80 | - public function isOpen (): bool; |
|
| 80 | + public function isOpen(): bool; |
|
| 81 | 81 | |
| 82 | 82 | } |
| 83 | 83 | \ No newline at end of file |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * |
| 13 | 13 | * @return int |
| 14 | 14 | */ |
| 15 | - final public static function getType (): int { |
|
| 15 | + final public static function getType(): int { |
|
| 16 | 16 | return SOCK_DGRAM; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @throws SocketError |
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | - public function recv ($length, $flags = 0, &$name = null, &$port = 0) { |
|
| 31 | + public function recv($length, $flags = 0, &$name = null, &$port = 0) { |
|
| 32 | 32 | $count = @socket_recvfrom($this->resource, $data, $length, $flags, $name, $port); |
| 33 | 33 | if ($count === false) { |
| 34 | 34 | throw new SocketError($this->resource, SOCKET_EOPNOTSUPP); |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * |
| 13 | 13 | * @return int |
| 14 | 14 | */ |
| 15 | - final public static function getType (): int { |
|
| 15 | + final public static function getType(): int { |
|
| 16 | 16 | return SOCK_STREAM; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @throws SocketError |
| 26 | 26 | * @return StreamClient The accepted connection, as a client instance. |
| 27 | 27 | */ |
| 28 | - public function accept () { |
|
| 28 | + public function accept() { |
|
| 29 | 29 | if (!$resource = @socket_accept($this->resource)) { |
| 30 | 30 | throw new SocketError($this->resource); // reliable errno |
| 31 | 31 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @throws SocketError |
| 43 | 43 | * @return $this |
| 44 | 44 | */ |
| 45 | - public function listen ($backlog = 0) { |
|
| 45 | + public function listen($backlog = 0) { |
|
| 46 | 46 | if (!@socket_listen($this->resource, $backlog)) { |
| 47 | 47 | throw new SocketError($this->resource); // reliable errno |
| 48 | 48 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @return StreamClient |
| 57 | 57 | * @throws SocketError |
| 58 | 58 | */ |
| 59 | - protected function newClient ($resource) { |
|
| 59 | + protected function newClient($resource) { |
|
| 60 | 60 | return new StreamClient($resource); |
| 61 | 61 | } |
| 62 | 62 | |