@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @param bool $final |
| 26 | 26 | * @return string |
| 27 | 27 | */ |
| 28 | - public static function pack (string $payload, int $opCode = self::OP_TEXT, bool $final = true): string { |
|
| 28 | + public static function pack(string $payload, int $opCode = self::OP_TEXT, bool $final = true): string { |
|
| 29 | 29 | $frame = chr(0x80 | $opCode); |
| 30 | 30 | $len = strlen($payload); |
| 31 | 31 | if ($len > 65535) { |
@@ -39,14 +39,14 @@ discard block |
||
| 39 | 39 | else { |
| 40 | 40 | $frame .= chr($len); |
| 41 | 41 | } |
| 42 | - return $frame . $payload; |
|
| 42 | + return $frame.$payload; |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public function __construct (string $data) { |
|
| 45 | + public function __construct(string $data) { |
|
| 46 | 46 | $this->data = $data; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - final public function getLength () { |
|
| 49 | + final public function getLength() { |
|
| 50 | 50 | switch ($char = ord($this->data[1]) & 0x7f) { |
| 51 | 51 | case 127: // big-endian long-long |
| 52 | 52 | return unpack('J', substr($this->data, 2, 8)); |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | /** |
| 61 | 61 | * @return int[] |
| 62 | 62 | */ |
| 63 | - final public function getMask () { |
|
| 63 | + final public function getMask() { |
|
| 64 | 64 | if ($this->isMasked()) { |
| 65 | 65 | switch (ord($this->data[1]) & 0x7f) { |
| 66 | 66 | case 127: |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | return [0, 0, 0, 0]; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - final public function getOpCode (): int { |
|
| 77 | + final public function getOpCode(): int { |
|
| 78 | 78 | return ord($this->data[0]) & 0x0f; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - final public function getPayload (): string { |
|
| 81 | + final public function getPayload(): string { |
|
| 82 | 82 | $length = $this->getLength(); |
| 83 | 83 | if ($length === 0) { |
| 84 | 84 | return ''; |
@@ -102,27 +102,27 @@ discard block |
||
| 102 | 102 | return $decoded; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - final public function isBinary (): bool { |
|
| 105 | + final public function isBinary(): bool { |
|
| 106 | 106 | return $this->getOpCode() === self::OP_BINARY; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - final public function isClose (): bool { |
|
| 109 | + final public function isClose(): bool { |
|
| 110 | 110 | return $this->getOpCode() === self::OP_CLOSE; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - final public function isFinal (): bool { |
|
| 113 | + final public function isFinal(): bool { |
|
| 114 | 114 | return (bool)(ord($this->data[0]) & 0x80); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - final public function isMasked (): bool { |
|
| 117 | + final public function isMasked(): bool { |
|
| 118 | 118 | return (bool)(ord($this->data[1]) & 0x80); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - final public function isPong (): bool { |
|
| 121 | + final public function isPong(): bool { |
|
| 122 | 122 | return $this->getOpCode() === self::OP_PONG; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - final public function isText (): bool { |
|
| 125 | + final public function isText(): bool { |
|
| 126 | 126 | return $this->getOpCode() === self::OP_TEXT; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -14,13 +14,13 @@ |
||
| 14 | 14 | * |
| 15 | 15 | * @return void |
| 16 | 16 | */ |
| 17 | - public function onOutOfBand (); |
|
| 17 | + public function onOutOfBand(); |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Called by the reactor when the socket has readable data. |
| 21 | 21 | * |
| 22 | 22 | * @return void |
| 23 | 23 | */ |
| 24 | - public function onReadable (); |
|
| 24 | + public function onReadable(); |
|
| 25 | 25 | |
| 26 | 26 | } |
| 27 | 27 | \ No newline at end of file |
@@ -42,34 +42,34 @@ |
||
| 42 | 42 | * |
| 43 | 43 | * @return int `SOCK_*` |
| 44 | 44 | */ |
| 45 | - public static function getType (); |
|
| 45 | + public static function getType(); |
|
| 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 (); |
|
| 52 | + public function getDomain(); |
|
| 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 (); |
|
| 59 | + public function getId(); |
|
| 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 (); |
|
| 66 | + public function getProtocol(); |
|
| 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 | \ No newline at end of file |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * |
| 15 | 15 | * @return string |
| 16 | 16 | */ |
| 17 | - public function __toString () { |
|
| 17 | + public function __toString() { |
|
| 18 | 18 | try { |
| 19 | 19 | return implode(':', $this->getSockName()); |
| 20 | 20 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @throws Error |
| 37 | 37 | * @return $this |
| 38 | 38 | */ |
| 39 | - public function bind (string $address, int $port = 0) { |
|
| 39 | + public function bind(string $address, int $port = 0) { |
|
| 40 | 40 | if (!@socket_bind($this->resource, $address, $port)) { |
| 41 | 41 | throw new Error($this->resource, SOCKET_EOPNOTSUPP); |
| 42 | 42 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * @param $resource |
| 24 | 24 | * @param Reactor $reactor |
| 25 | 25 | */ |
| 26 | - public function __construct ($resource, Reactor $reactor) { |
|
| 26 | + public function __construct($resource, Reactor $reactor) { |
|
| 27 | 27 | parent::__construct($resource); |
| 28 | 28 | $reactor->add($this); |
| 29 | 29 | $this->reactor = $reactor; |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * https://tools.ietf.org/html/rfc6455#section-4.2 |
| 36 | 36 | * @return WebSocketClient |
| 37 | 37 | */ |
| 38 | - public function accept () { |
|
| 38 | + public function accept() { |
|
| 39 | 39 | if (!$resource = @socket_accept($this->resource)) { |
| 40 | 40 | throw new Error($this->resource); // reliable errno |
| 41 | 41 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | /** |
| 51 | 51 | * @param WebSocketClient $client |
| 52 | 52 | */ |
| 53 | - protected function acceptHandshake (WebSocketClient $client) { |
|
| 53 | + protected function acceptHandshake(WebSocketClient $client) { |
|
| 54 | 54 | $head = $client->await(self::CH_READ)->recv(4096); // todo client->readUntil(string,maxlength) |
| 55 | 55 | $head = explode("\r\n", $head); |
| 56 | 56 | $method = array_shift($head); |
@@ -78,17 +78,17 @@ discard block |
||
| 78 | 78 | "HTTP/1.1 101 Switching Protocols", |
| 79 | 79 | "Upgrade: websocket", |
| 80 | 80 | "Connection: Upgrade", |
| 81 | - "Sec-WebSocket-Accept: " . base64_encode(sha1($base64Key . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11', true)), |
|
| 81 | + "Sec-WebSocket-Accept: ".base64_encode(sha1($base64Key.'258EAFA5-E914-47DA-95CA-C5AB0DC85B11', true)), |
|
| 82 | 82 | ]; |
| 83 | 83 | |
| 84 | - $client->write(implode("\r\n", $response) . "\r\n\r\n"); |
|
| 84 | + $client->write(implode("\r\n", $response)."\r\n\r\n"); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * @param WebSocketClient $client |
| 89 | 89 | * @param string $connection |
| 90 | 90 | */ |
| 91 | - protected function acceptHandshakeConnection (WebSocketClient $client, string $connection) { |
|
| 91 | + protected function acceptHandshakeConnection(WebSocketClient $client, string $connection) { |
|
| 92 | 92 | if (!preg_match('/^upgrade$/i', $connection)) { |
| 93 | 93 | $this->reject($client, "Expected: Connection: Upgrade"); |
| 94 | 94 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * @param WebSocketClient $client |
| 101 | 101 | * @param string $host |
| 102 | 102 | */ |
| 103 | - protected function acceptHandshakeHost (WebSocketClient $client, string $host) { |
|
| 103 | + protected function acceptHandshakeHost(WebSocketClient $client, string $host) { |
|
| 104 | 104 | |
| 105 | 105 | } |
| 106 | 106 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * @param WebSocketClient $client |
| 109 | 109 | * @param string $base64Key |
| 110 | 110 | */ |
| 111 | - protected function acceptHandshakeKey (WebSocketClient $client, string $base64Key) { |
|
| 111 | + protected function acceptHandshakeKey(WebSocketClient $client, string $base64Key) { |
|
| 112 | 112 | $key = base64_decode($base64Key); |
| 113 | 113 | if ($key === false or strlen($key) !== 16) { |
| 114 | 114 | $this->reject($client, "Expected Sec-WebSocket-Key"); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @param WebSocketClient $client |
| 120 | 120 | * @param string $method |
| 121 | 121 | */ |
| 122 | - protected function acceptHandshakeMethod (WebSocketClient $client, string $method) { |
|
| 122 | + protected function acceptHandshakeMethod(WebSocketClient $client, string $method) { |
|
| 123 | 123 | if (!preg_match('/HTTP\/1\.1$/i', $method)) { |
| 124 | 124 | $this->reject($client, "Expected: HTTP/1.1"); |
| 125 | 125 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * @param WebSocketClient $client |
| 132 | 132 | * @param string $origin |
| 133 | 133 | */ |
| 134 | - protected function acceptHandshakeOrigin (WebSocketClient $client, string $origin) { |
|
| 134 | + protected function acceptHandshakeOrigin(WebSocketClient $client, string $origin) { |
|
| 135 | 135 | |
| 136 | 136 | } |
| 137 | 137 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @param WebSocketClient $client |
| 140 | 140 | * @param string $upgrade |
| 141 | 141 | */ |
| 142 | - protected function acceptHandshakeUpgrade (WebSocketClient $client, string $upgrade) { |
|
| 142 | + protected function acceptHandshakeUpgrade(WebSocketClient $client, string $upgrade) { |
|
| 143 | 143 | if (!preg_match('/^websocket$/i', $upgrade)) { |
| 144 | 144 | $this->reject($client, "Expected Upgrade: websocket"); |
| 145 | 145 | } |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @param WebSocketClient $client |
| 150 | 150 | * @param string $version |
| 151 | 151 | */ |
| 152 | - protected function acceptHandshakeVersion (WebSocketClient $client, string $version) { |
|
| 152 | + protected function acceptHandshakeVersion(WebSocketClient $client, string $version) { |
|
| 153 | 153 | if ($version !== '13') { |
| 154 | 154 | $this->reject($client, "Expected Sec-WebSocket-Version: 13"); |
| 155 | 155 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | /** |
| 159 | 159 | * @return WebSocketClient[] |
| 160 | 160 | */ |
| 161 | - public function getClients () { |
|
| 161 | + public function getClients() { |
|
| 162 | 162 | return $this->clients; |
| 163 | 163 | } |
| 164 | 164 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @param resource $resource |
| 167 | 167 | * @return WebSocketClient |
| 168 | 168 | */ |
| 169 | - protected function newClient ($resource) { |
|
| 169 | + protected function newClient($resource) { |
|
| 170 | 170 | return new WebSocketClient($resource, $this); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -175,14 +175,14 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @inheritDoc |
| 177 | 177 | */ |
| 178 | - final public function onOutOfBand () { |
|
| 178 | + final public function onOutOfBand() { |
|
| 179 | 179 | // do nothing |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
| 183 | 183 | * @inheritDoc |
| 184 | 184 | */ |
| 185 | - public function onReadable () { |
|
| 185 | + public function onReadable() { |
|
| 186 | 186 | $this->accept(); |
| 187 | 187 | } |
| 188 | 188 | |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * @param string $reason |
| 194 | 194 | * @throws RuntimeException |
| 195 | 195 | */ |
| 196 | - protected function reject (WebSocketClient $client, string $reason) { |
|
| 196 | + protected function reject(WebSocketClient $client, string $reason) { |
|
| 197 | 197 | throw new RuntimeException("Rejected {$client}: {$reason}"); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * @param WebSocketClient $client |
| 204 | 204 | * @return $this |
| 205 | 205 | */ |
| 206 | - public function remove (WebSocketClient $client) { |
|
| 206 | + public function remove(WebSocketClient $client) { |
|
| 207 | 207 | unset($this->clients[$client->getId()]); |
| 208 | 208 | $this->reactor->remove($client->getId()); |
| 209 | 209 | return $this; |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * @return static[] Two instances at indices `0` and `1`. |
| 18 | 18 | * @throws Error |
| 19 | 19 | */ |
| 20 | - public static function newUnixPair (...$extra) { |
|
| 20 | + public static function newUnixPair(...$extra) { |
|
| 21 | 21 | if (!@socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $fd)) { |
| 22 | 22 | throw new Error; // reliable errno |
| 23 | 23 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @return int |
| 34 | 34 | */ |
| 35 | - final public static function getType () { |
|
| 35 | + final public static function getType() { |
|
| 36 | 36 | return SOCK_STREAM; |
| 37 | 37 | } |
| 38 | 38 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @return string |
| 47 | 47 | * @throws Error The error's extra data is set to what was partially read. |
| 48 | 48 | */ |
| 49 | - public function read ($length) { |
|
| 49 | + public function read($length) { |
|
| 50 | 50 | $data = ''; |
| 51 | 51 | while ($length > 0) { |
| 52 | 52 | try { |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @throws Error |
| 77 | 77 | * @return string |
| 78 | 78 | */ |
| 79 | - public function recv ($length, $flags = 0) { |
|
| 79 | + public function recv($length, $flags = 0) { |
|
| 80 | 80 | $count = @socket_recv($this->resource, $data, $length, $flags); |
| 81 | 81 | if ($count === false) { |
| 82 | 82 | $error = new Error($this->resource, SOCKET_EINVAL); |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @param $resource |
| 19 | 19 | * @param WebSocketServer $server |
| 20 | 20 | */ |
| 21 | - public function __construct ($resource, WebSocketServer $server) { |
|
| 21 | + public function __construct($resource, WebSocketServer $server) { |
|
| 22 | 22 | parent::__construct($resource); |
| 23 | 23 | $this->server = $server; |
| 24 | 24 | } |
@@ -26,33 +26,33 @@ discard block |
||
| 26 | 26 | /** |
| 27 | 27 | * Removes the client from the server and reactor. |
| 28 | 28 | */ |
| 29 | - protected function onClose () { |
|
| 29 | + protected function onClose() { |
|
| 30 | 30 | $this->server->remove($this); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * @param string $payload |
| 35 | 35 | */ |
| 36 | - protected function onData (string $payload): void { |
|
| 36 | + protected function onData(string $payload): void { |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * WebSockets do not use the out-of-band channel. |
| 41 | 41 | */ |
| 42 | - final public function onOutOfBand () { |
|
| 42 | + final public function onOutOfBand() { |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * When a browser responds to a ping. |
| 47 | 47 | */ |
| 48 | - protected function onPong (): void { |
|
| 48 | + protected function onPong(): void { |
|
| 49 | 49 | // stub |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * Reads framed messages. |
| 54 | 54 | */ |
| 55 | - public function onReadable (): void { |
|
| 55 | + public function onReadable(): void { |
|
| 56 | 56 | $data = $this->recv(4096); |
| 57 | 57 | $frame = new WebSocketFrame($data); |
| 58 | 58 | if ($frame->isText()) { |
@@ -74,17 +74,17 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @param string $text |
| 76 | 76 | */ |
| 77 | - protected function onText (string $text): void { |
|
| 77 | + protected function onText(string $text): void { |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Pings the browser. |
| 82 | 82 | */ |
| 83 | - public function ping () { |
|
| 83 | + public function ping() { |
|
| 84 | 84 | $this->write(WebSocketFrame::pack('', WebSocketFrame::OP_PING)); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function writeText (string $message) { |
|
| 87 | + public function writeText(string $message) { |
|
| 88 | 88 | $packed = WebSocketFrame::pack($message); |
| 89 | 89 | $this->write($packed); |
| 90 | 90 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * |
| 13 | 13 | * @return int |
| 14 | 14 | */ |
| 15 | - final public static function getType () { |
|
| 15 | + final public static function getType() { |
|
| 16 | 16 | return SOCK_STREAM; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * @throws Error |
| 28 | 28 | * @return StreamClient The accepted connection, as a client instance. |
| 29 | 29 | */ |
| 30 | - public function accept () { |
|
| 30 | + public function accept() { |
|
| 31 | 31 | if (!$resource = @socket_accept($this->resource)) { |
| 32 | 32 | throw new Error($this->resource); // reliable errno |
| 33 | 33 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @throws Error |
| 47 | 47 | * @return $this |
| 48 | 48 | */ |
| 49 | - public function listen ($backlog = 0) { |
|
| 49 | + public function listen($backlog = 0) { |
|
| 50 | 50 | if (!@socket_listen($this->resource, $backlog)) { |
| 51 | 51 | throw new Error($this->resource); // reliable errno |
| 52 | 52 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @return StreamClient |
| 61 | 61 | * @throws Error |
| 62 | 62 | */ |
| 63 | - protected function newClient ($resource) { |
|
| 63 | + protected function newClient($resource) { |
|
| 64 | 64 | return new StreamClient($resource); |
| 65 | 65 | } |
| 66 | 66 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @param StreamClient $client |
| 71 | 71 | * @return void |
| 72 | 72 | */ |
| 73 | - protected function onAccept (StreamClient $client) { |
|
| 73 | + protected function onAccept(StreamClient $client) { |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @return static |
| 42 | 42 | * @throws Error |
| 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 Error; // reliable errno |
| 47 | 47 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @return int |
| 61 | 61 | * @throws Error |
| 62 | 62 | */ |
| 63 | - public static function select (array &$read, array &$write, array &$except, $timeout = null) { |
|
| 63 | + public static function select(array &$read, array &$write, array &$except, $timeout = null) { |
|
| 64 | 64 | $getResource = function(SocketInterface $socket) { |
| 65 | 65 | return $socket->getResource(); |
| 66 | 66 | }; |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | * @throws Error (`SOCKET_EBADFD`) There was a pending error on the socket. |
| 91 | 91 | * The preexisting error code is set as the exception's extra data. |
| 92 | 92 | */ |
| 93 | - public function __construct ($resource) { |
|
| 93 | + public function __construct($resource) { |
|
| 94 | 94 | if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') { |
| 95 | 95 | throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF); |
| 96 | 96 | } |
| 97 | 97 | elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) { |
| 98 | - throw new InvalidArgumentException('The given socket resource is of the wrong type for ' . get_class(), SOCKET_ESOCKTNOSUPPORT); |
|
| 98 | + throw new InvalidArgumentException('The given socket resource is of the wrong type for '.get_class(), SOCKET_ESOCKTNOSUPPORT); |
|
| 99 | 99 | } |
| 100 | 100 | elseif ($errno = Error::getLast($resource)) { |
| 101 | 101 | $error = new Error(SOCKET_EBADFD); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | /** |
| 111 | 111 | * Closes the socket if it's open. |
| 112 | 112 | */ |
| 113 | - public function __destruct () { |
|
| 113 | + public function __destruct() { |
|
| 114 | 114 | $this->close(); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @return $this |
| 126 | 126 | * @throws Error |
| 127 | 127 | */ |
| 128 | - public function await ($channel) { |
|
| 128 | + public function await($channel) { |
|
| 129 | 129 | $select = [$channel => [$this->resource]]; |
| 130 | 130 | $count = @socket_select($select[self::CH_READ], $select[self::CH_WRITE], $select[self::CH_EXCEPT], null); |
| 131 | 131 | if (!$count) { |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @return $this |
| 146 | 146 | */ |
| 147 | - public function close () { |
|
| 147 | + public function close() { |
|
| 148 | 148 | // socket_close() never errors, but we guard anyway to prevent |
| 149 | 149 | // a redundant call to onClose(), and an incorrect call to it if |
| 150 | 150 | // the constructor failed and the destructor is calling this. |
@@ -158,14 +158,14 @@ discard block |
||
| 158 | 158 | /** |
| 159 | 159 | * @return int |
| 160 | 160 | */ |
| 161 | - final public function getDomain () { |
|
| 161 | + final public function getDomain() { |
|
| 162 | 162 | return $this->domain; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | 166 | * @return int |
| 167 | 167 | */ |
| 168 | - final public function getId () { |
|
| 168 | + final public function getId() { |
|
| 169 | 169 | return (int)$this->resource; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * @throws Error |
| 179 | 179 | * @return mixed The option's value. This is never `false`. |
| 180 | 180 | */ |
| 181 | - public function getOption ($option) { |
|
| 181 | + public function getOption($option) { |
|
| 182 | 182 | $value = @socket_get_option($this->resource, SOL_SOCKET, $option); |
| 183 | 183 | if ($value === false) { |
| 184 | 184 | throw new Error($this->resource, SOCKET_EINVAL); |
@@ -189,14 +189,14 @@ discard block |
||
| 189 | 189 | /** |
| 190 | 190 | * @return int |
| 191 | 191 | */ |
| 192 | - final public function getProtocol () { |
|
| 192 | + final public function getProtocol() { |
|
| 193 | 193 | return $this->protocol; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
| 197 | 197 | * @return resource |
| 198 | 198 | */ |
| 199 | - final public function getResource () { |
|
| 199 | + final public function getResource() { |
|
| 200 | 200 | return $this->resource; |
| 201 | 201 | } |
| 202 | 202 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @throws Error |
| 209 | 209 | * @return array String address/file and integer port at indices `0` and `1`. |
| 210 | 210 | */ |
| 211 | - public function getSockName () { |
|
| 211 | + public function getSockName() { |
|
| 212 | 212 | if (!@socket_getsockname($this->resource, $addr, $port)) { |
| 213 | 213 | throw new Error($this->resource, SOCKET_EOPNOTSUPP); |
| 214 | 214 | } |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * |
| 221 | 221 | * @return bool |
| 222 | 222 | */ |
| 223 | - public function isOpen () { |
|
| 223 | + public function isOpen() { |
|
| 224 | 224 | return is_resource($this->resource); |
| 225 | 225 | } |
| 226 | 226 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * @return bool |
| 233 | 233 | * @throws Error |
| 234 | 234 | */ |
| 235 | - public function isOutOfBand () { |
|
| 235 | + public function isOutOfBand() { |
|
| 236 | 236 | return $this->isReady(self::CH_EXCEPT); |
| 237 | 237 | } |
| 238 | 238 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * @return bool |
| 245 | 245 | * @throws Error |
| 246 | 246 | */ |
| 247 | - final public function isReadable () { |
|
| 247 | + final public function isReadable() { |
|
| 248 | 248 | return $this->isReady(self::CH_READ); |
| 249 | 249 | } |
| 250 | 250 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @return bool |
| 259 | 259 | * @throws Error |
| 260 | 260 | */ |
| 261 | - public function isReady ($channel, $timeout = 0.0) { |
|
| 261 | + public function isReady($channel, $timeout = 0.0) { |
|
| 262 | 262 | $usec = (int)(fmod($timeout, 1) * 1000000); // ignored if timeout is null |
| 263 | 263 | $select = [$channel => [$this->resource]]; |
| 264 | 264 | $count = $count = @socket_select( |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @return bool |
| 283 | 283 | * @throws Error |
| 284 | 284 | */ |
| 285 | - final public function isWritable () { |
|
| 285 | + final public function isWritable() { |
|
| 286 | 286 | return $this->isReady(self::CH_WRITE); |
| 287 | 287 | } |
| 288 | 288 | |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * |
| 292 | 292 | * @return void |
| 293 | 293 | */ |
| 294 | - protected function onClose () { |
|
| 294 | + protected function onClose() { |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * @param int $channel `SocketInterface` channel constant. |
| 301 | 301 | * @return void |
| 302 | 302 | */ |
| 303 | - protected function onShutdown ($channel) { |
|
| 303 | + protected function onShutdown($channel) { |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | * |
| 309 | 309 | * @return void |
| 310 | 310 | */ |
| 311 | - protected function onTimeout () { |
|
| 311 | + protected function onTimeout() { |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * @throws Error |
| 330 | 330 | * @return $this |
| 331 | 331 | */ |
| 332 | - public function setBlocking ($blocking) { |
|
| 332 | + public function setBlocking($blocking) { |
|
| 333 | 333 | if ($blocking) { |
| 334 | 334 | $success = @socket_set_block($this->resource); |
| 335 | 335 | } |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | * @throws Error |
| 353 | 353 | * @return $this |
| 354 | 354 | */ |
| 355 | - public function setOption ($option, $value) { |
|
| 355 | + public function setOption($option, $value) { |
|
| 356 | 356 | if (!@socket_set_option($this->resource, SOL_SOCKET, $option, $value)) { |
| 357 | 357 | throw new Error($this->resource, SOCKET_EINVAL); |
| 358 | 358 | } |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | * @return $this |
| 367 | 367 | * @throws Error |
| 368 | 368 | */ |
| 369 | - public function setTimeout ($timeout) { |
|
| 369 | + public function setTimeout($timeout) { |
|
| 370 | 370 | $timeval = ['sec' => (int)$timeout, 'usec' => (int)(fmod($timeout, 1) * 1000000)]; |
| 371 | 371 | $this->setOption(SO_RCVTIMEO, $timeval); |
| 372 | 372 | $this->setOption(SO_SNDTIMEO, $timeval); |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | * @throws Error |
| 394 | 394 | * @return $this |
| 395 | 395 | */ |
| 396 | - public function shutdown ($channel) { |
|
| 396 | + public function shutdown($channel) { |
|
| 397 | 397 | $this->onShutdown($channel); |
| 398 | 398 | if (!@socket_shutdown($this->resource, $channel)) { |
| 399 | 399 | throw new Error($this->resource); // reliable errno |