@@ -61,11 +61,9 @@ discard block |
||
| 61 | 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 | - } |
|
| 65 | - elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) { |
|
| 64 | + } elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) { |
|
| 66 | 65 | throw new InvalidArgumentException('The given socket resource is of the wrong type for ' . get_class(), SOCKET_ESOCKTNOSUPPORT); |
| 67 | - } |
|
| 68 | - elseif ($errno = SocketError::getLast($resource)) { |
|
| 66 | + } elseif ($errno = SocketError::getLast($resource)) { |
|
| 69 | 67 | $error = new SocketError(SOCKET_EBADFD); |
| 70 | 68 | $error->setExtra($errno); |
| 71 | 69 | throw $error; |
@@ -289,8 +287,7 @@ discard block |
||
| 289 | 287 | public function setBlocking ($blocking) { |
| 290 | 288 | if ($blocking) { |
| 291 | 289 | $success = @socket_set_block($this->resource); |
| 292 | - } |
|
| 293 | - else { |
|
| 290 | + } else { |
|
| 294 | 291 | $success = @socket_set_nonblock($this->resource); |
| 295 | 292 | } |
| 296 | 293 | if (!$success) { |
@@ -53,8 +53,7 @@ discard block |
||
| 53 | 53 | $length -= $chunkSize = strlen($chunk); |
| 54 | 54 | } while ($chunkSize and $length); |
| 55 | 55 | return $data; |
| 56 | - } |
|
| 57 | - catch (SocketError $error) { |
|
| 56 | + } catch (SocketError $error) { |
|
| 58 | 57 | $error->setExtra($data); |
| 59 | 58 | throw $error; |
| 60 | 59 | } |
@@ -90,8 +89,7 @@ discard block |
||
| 90 | 89 | $length = $this->getOption(SO_RCVBUF); |
| 91 | 90 | try { |
| 92 | 91 | return $this->recv($length, $msgFlags); |
| 93 | - } |
|
| 94 | - catch (SocketError $e) { |
|
| 92 | + } catch (SocketError $e) { |
|
| 95 | 93 | if ($e->getCode() === SOCKET_EAGAIN) { // would block |
| 96 | 94 | return ''; |
| 97 | 95 | } |
@@ -93,8 +93,7 @@ |
||
| 93 | 93 | foreach ($rwe[0] as $id => $socket) { |
| 94 | 94 | $socket->onReadable(); |
| 95 | 95 | } |
| 96 | - } |
|
| 97 | - finally { |
|
| 96 | + } finally { |
|
| 98 | 97 | array_walk_recursive($rwe, function(ReactiveInterface $each) { |
| 99 | 98 | if (!$each->isOpen()) { |
| 100 | 99 | $this->remove($each); |
@@ -57,14 +57,12 @@ |
||
| 57 | 57 | public function __construct ($subject = null, $fallback = 0) { |
| 58 | 58 | if (is_int($subject)) { |
| 59 | 59 | $errno = $subject; |
| 60 | - } |
|
| 61 | - else { |
|
| 60 | + } else { |
|
| 62 | 61 | $errno = static::getLast($subject); |
| 63 | 62 | } |
| 64 | 63 | if ($errno) { |
| 65 | 64 | $message = socket_strerror($errno); |
| 66 | - } |
|
| 67 | - else { |
|
| 65 | + } else { |
|
| 68 | 66 | $errno = $fallback; |
| 69 | 67 | $message = error_get_last()['message']; |
| 70 | 68 | } |
@@ -19,8 +19,7 @@ |
||
| 19 | 19 | public function __toString () { |
| 20 | 20 | try { |
| 21 | 21 | return implode(':', $this->getSockName()); |
| 22 | - } |
|
| 23 | - catch (Exception $exception) { |
|
| 22 | + } catch (Exception $exception) { |
|
| 24 | 23 | return ':'; |
| 25 | 24 | } |
| 26 | 25 | } |
@@ -19,8 +19,7 @@ discard block |
||
| 19 | 19 | public function __toString () { |
| 20 | 20 | try { |
| 21 | 21 | return implode(':', $this->getPeerName()); |
| 22 | - } |
|
| 23 | - catch (Exception $exception) { |
|
| 22 | + } catch (Exception $exception) { |
|
| 24 | 23 | return ':'; |
| 25 | 24 | } |
| 26 | 25 | } |
@@ -102,8 +101,7 @@ discard block |
||
| 102 | 101 | while ($total < $length) { |
| 103 | 102 | try { |
| 104 | 103 | $total += $this->awaitWritable()->send(substr($data, $total)); |
| 105 | - } |
|
| 106 | - catch (SocketError $error) { |
|
| 104 | + } catch (SocketError $error) { |
|
| 107 | 105 | $error->setExtra($total); |
| 108 | 106 | throw $error; |
| 109 | 107 | } |
@@ -91,8 +91,7 @@ discard block |
||
| 91 | 91 | $value = trim($value); |
| 92 | 92 | if (isset($this->headers[$key])) { |
| 93 | 93 | $this->headers[$key] .= ', ' . $value; |
| 94 | - } |
|
| 95 | - else { |
|
| 94 | + } else { |
|
| 96 | 95 | $this->headers[$key] = $value; |
| 97 | 96 | } |
| 98 | 97 | } |
@@ -101,8 +100,7 @@ discard block |
||
| 101 | 100 | $this->upgrade(); |
| 102 | 101 | $this->client->write("\r\n\r\n"); |
| 103 | 102 | return true; |
| 104 | - } |
|
| 105 | - catch (WebSocketError $e) { |
|
| 103 | + } catch (WebSocketError $e) { |
|
| 106 | 104 | $this->client->write("HTTP/1.1 {$e->getCode()}\r\n\r\n"); |
| 107 | 105 | throw $e; |
| 108 | 106 | } |
@@ -94,8 +94,7 @@ |
||
| 94 | 94 | foreach ($this->clients as $client) { |
| 95 | 95 | try { |
| 96 | 96 | $client->close($code, $reason); |
| 97 | - } |
|
| 98 | - catch (Exception $e) { |
|
| 97 | + } catch (Exception $e) { |
|
| 99 | 98 | continue; |
| 100 | 99 | } |
| 101 | 100 | } |
@@ -81,8 +81,7 @@ discard block |
||
| 81 | 81 | $this->getFrameHandler()->write($payload, Frame::OP_CLOSE); |
| 82 | 82 | $this->shutdown(self::CH_WRITE); |
| 83 | 83 | } |
| 84 | - } |
|
| 85 | - finally { |
|
| 84 | + } finally { |
|
| 86 | 85 | $this->state = self::STATE_CLOSE; |
| 87 | 86 | $this->server->remove($this); |
| 88 | 87 | parent::close(); |
@@ -174,12 +173,10 @@ discard block |
||
| 174 | 173 | case self::STATE_CLOSE: |
| 175 | 174 | return; |
| 176 | 175 | } |
| 177 | - } |
|
| 178 | - catch (WebSocketError $e) { |
|
| 176 | + } catch (WebSocketError $e) { |
|
| 179 | 177 | $this->close($e->getCode(), $e->getMessage()); |
| 180 | 178 | throw $e; |
| 181 | - } |
|
| 182 | - catch (Exception $e) { |
|
| 179 | + } catch (Exception $e) { |
|
| 183 | 180 | $this->close(Frame::CLOSE_INTERNAL_ERROR); |
| 184 | 181 | throw $e; |
| 185 | 182 | } |