@@ -155,7 +155,7 @@ |
||
| 155 | 155 | private function setConnectionFinishTime(OperationMetadata $operationMetadata) |
| 156 | 156 | { |
| 157 | 157 | $meta = $operationMetadata->getMetadata(); |
| 158 | - $wasConnected = $meta[ RequestExecutorInterface::META_CONNECTION_FINISH_TIME ] !== null; |
|
| 158 | + $wasConnected = $meta[RequestExecutorInterface::META_CONNECTION_FINISH_TIME] !== null; |
|
| 159 | 159 | $this->setSocketOperationTime($operationMetadata, RequestExecutorInterface::META_CONNECTION_FINISH_TIME); |
| 160 | 160 | if (!$wasConnected) { |
| 161 | 161 | $event = $this->createEvent($operationMetadata, EventType::CONNECTED); |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Async sockets |
|
| 4 | - * |
|
| 5 | - * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | - * |
|
| 7 | - * This source file is subject to the MIT license that is bundled |
|
| 8 | - * with this source code in the file LICENSE. |
|
| 9 | - */ |
|
| 3 | + * Async sockets |
|
| 4 | + * |
|
| 5 | + * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | + * |
|
| 7 | + * This source file is subject to the MIT license that is bundled |
|
| 8 | + * with this source code in the file LICENSE. |
|
| 9 | + */ |
|
| 10 | 10 | namespace AsyncSockets\Socket; |
| 11 | 11 | |
| 12 | 12 | use AsyncSockets\Frame\FramePickerInterface; |
@@ -105,13 +105,13 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | private function getStreamContextFromMetaData($meta) |
| 107 | 107 | { |
| 108 | - $metaStreamContext = $meta[ RequestExecutorInterface::META_SOCKET_STREAM_CONTEXT ]; |
|
| 108 | + $metaStreamContext = $meta[RequestExecutorInterface::META_SOCKET_STREAM_CONTEXT]; |
|
| 109 | 109 | if (is_resource($metaStreamContext)) { |
| 110 | 110 | return $metaStreamContext; |
| 111 | 111 | } elseif (is_array($metaStreamContext)) { |
| 112 | 112 | return stream_context_create( |
| 113 | - isset($metaStreamContext[ 'options' ]) ? $metaStreamContext[ 'options' ] : [ ], |
|
| 114 | - isset($metaStreamContext[ 'params' ]) ? $metaStreamContext[ 'params' ] : [ ] |
|
| 113 | + isset($metaStreamContext['options']) ? $metaStreamContext['options'] : [], |
|
| 114 | + isset($metaStreamContext['params']) ? $metaStreamContext['params'] : [] |
|
| 115 | 115 | ); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | $this->setSocketOperationTime($item, RequestExecutorInterface::META_CONNECTION_START_TIME); |
| 139 | 139 | |
| 140 | 140 | $socket->open( |
| 141 | - $meta[ RequestExecutorInterface::META_ADDRESS ], |
|
| 141 | + $meta[RequestExecutorInterface::META_ADDRESS], |
|
| 142 | 142 | $this->getStreamContextFromMetaData($meta) |
| 143 | 143 | ); |
| 144 | 144 | |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Async sockets |
|
| 4 | - * |
|
| 5 | - * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | - * |
|
| 7 | - * This source file is subject to the MIT license that is bundled |
|
| 8 | - * with this source code in the file LICENSE. |
|
| 9 | - */ |
|
| 3 | + * Async sockets |
|
| 4 | + * |
|
| 5 | + * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | + * |
|
| 7 | + * This source file is subject to the MIT license that is bundled |
|
| 8 | + * with this source code in the file LICENSE. |
|
| 9 | + */ |
|
| 10 | 10 | namespace AsyncSockets\Socket; |
| 11 | 11 | |
| 12 | 12 | use AsyncSockets\Frame\FramePickerInterface; |
@@ -75,15 +75,13 @@ |
||
| 75 | 75 | { |
| 76 | 76 | switch ($type) { |
| 77 | 77 | case self::SOCKET_CLIENT: |
| 78 | - $isPersistent = isset($options[ self::SOCKET_OPTION_IS_PERSISTENT ]) && |
|
| 79 | - $options[ self::SOCKET_OPTION_IS_PERSISTENT ]; |
|
| 80 | - $persistentKey = isset($options[ self::SOCKET_OPTION_PERSISTENT_KEY ]) ? |
|
| 81 | - $options[ self::SOCKET_OPTION_PERSISTENT_KEY ] : |
|
| 82 | - null; |
|
| 78 | + $isPersistent = isset($options[self::SOCKET_OPTION_IS_PERSISTENT]) && |
|
| 79 | + $options[self::SOCKET_OPTION_IS_PERSISTENT]; |
|
| 80 | + $persistentKey = isset($options[self::SOCKET_OPTION_PERSISTENT_KEY]) ? |
|
| 81 | + $options[self::SOCKET_OPTION_PERSISTENT_KEY] : null; |
|
| 83 | 82 | |
| 84 | 83 | return $isPersistent ? |
| 85 | - new PersistentClientSocket($persistentKey) : |
|
| 86 | - new ClientSocket(); |
|
| 84 | + new PersistentClientSocket($persistentKey) : new ClientSocket(); |
|
| 87 | 85 | case self::SOCKET_SERVER: |
| 88 | 86 | return new ServerSocket(); |
| 89 | 87 | default: |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Async sockets |
|
| 4 | - * |
|
| 5 | - * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | - * |
|
| 7 | - * This source file is subject to the MIT license that is bundled |
|
| 8 | - * with this source code in the file LICENSE. |
|
| 9 | - */ |
|
| 3 | + * Async sockets |
|
| 4 | + * |
|
| 5 | + * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | + * |
|
| 7 | + * This source file is subject to the MIT license that is bundled |
|
| 8 | + * with this source code in the file LICENSE. |
|
| 9 | + */ |
|
| 10 | 10 | namespace AsyncSockets\Socket; |
| 11 | 11 | |
| 12 | 12 | use AsyncSockets\Frame\FramePickerInterface; |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | public function processStage(array $operations) |
| 25 | 25 | { |
| 26 | 26 | /** @var OperationMetadata[] $operations */ |
| 27 | - $result = [ ]; |
|
| 27 | + $result = []; |
|
| 28 | 28 | $microTime = microtime(true); |
| 29 | 29 | foreach ($operations as $key => $operation) { |
| 30 | 30 | if ($this->isSingleSocketTimeout($operation, $microTime)) { |
@@ -53,8 +53,7 @@ discard block |
||
| 53 | 53 | $meta[RequestExecutorInterface::META_USER_CONTEXT], |
| 54 | 54 | $meta[RequestExecutorInterface::META_CONNECTION_FINISH_TIME] !== null && |
| 55 | 55 | !($descriptor->getSocket() instanceof ServerSocket) ? |
| 56 | - TimeoutEvent::DURING_IO : |
|
| 57 | - TimeoutEvent::DURING_CONNECTION |
|
| 56 | + TimeoutEvent::DURING_IO : TimeoutEvent::DURING_CONNECTION |
|
| 58 | 57 | ); |
| 59 | 58 | try { |
| 60 | 59 | $this->callSocketSubscribers($descriptor, $event); |
@@ -1,12 +1,12 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Async sockets |
|
| 4 | - * |
|
| 5 | - * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | - * |
|
| 7 | - * This source file is subject to the MIT license that is bundled |
|
| 8 | - * with this source code in the file LICENSE. |
|
| 9 | - */ |
|
| 3 | + * Async sockets |
|
| 4 | + * |
|
| 5 | + * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | + * |
|
| 7 | + * This source file is subject to the MIT license that is bundled |
|
| 8 | + * with this source code in the file LICENSE. |
|
| 9 | + */ |
|
| 10 | 10 | namespace AsyncSockets\RequestExecutor\Pipeline; |
| 11 | 11 | |
| 12 | 12 | use AsyncSockets\Event\TimeoutEvent; |
@@ -114,10 +114,10 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | return ($desiredTimeout !== RequestExecutorInterface::WAIT_FOREVER) && |
| 116 | 116 | ( |
| 117 | - ($hasConnected && $lastOperationTime !== null) || |
|
| 117 | + ($hasConnected && $lastOperationTime !== null) || |
|
| 118 | 118 | !$hasConnected |
| 119 | - ) && |
|
| 119 | + ) && |
|
| 120 | 120 | ($microTime - $lastOperationTime >= $desiredTimeout) |
| 121 | - ; |
|
| 121 | + ; |
|
| 122 | 122 | } |
| 123 | 123 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | return new self( |
| 30 | 30 | $socket, |
| 31 | 31 | sprintf( |
| 32 | - 'System has detected a zombie connection %s and closed it. '. |
|
| 32 | + 'System has detected a zombie connection %s and closed it. ' . |
|
| 33 | 33 | 'If you see this message it means that application ' . |
| 34 | 34 | 'has lost control on one of its sockets.', |
| 35 | 35 | (string) $socket |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | */ |
| 240 | 240 | public function removeAllSocketOperations(StreamResourceInterface $streamResource) |
| 241 | 241 | { |
| 242 | - $opList = [ OperationInterface::OPERATION_READ, |
|
| 243 | - OperationInterface::OPERATION_WRITE ]; |
|
| 242 | + $opList = [OperationInterface::OPERATION_READ, |
|
| 243 | + OperationInterface::OPERATION_WRITE]; |
|
| 244 | 244 | |
| 245 | 245 | foreach ($opList as $op) { |
| 246 | 246 | $this->removeSocketOperation($streamResource, $op); |
@@ -281,8 +281,7 @@ discard block |
||
| 281 | 281 | */ |
| 282 | 282 | private function calculateAttemptsCount($seconds, $usec) |
| 283 | 283 | { |
| 284 | - $result = $seconds !== null ? ceil(($seconds * 1E6 + $usec) / self::ATTEMPT_DELAY) : |
|
| 285 | - self::ATTEMPT_COUNT_FOR_INFINITE_TIMEOUT; |
|
| 284 | + $result = $seconds !== null ? ceil(($seconds * 1E6 + $usec) / self::ATTEMPT_DELAY) : self::ATTEMPT_COUNT_FOR_INFINITE_TIMEOUT; |
|
| 286 | 285 | if ($result < self::ATTEMPT_COUNT_FOR_INFINITE_TIMEOUT) { |
| 287 | 286 | $result = self::ATTEMPT_COUNT_FOR_INFINITE_TIMEOUT; |
| 288 | 287 | } |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Async sockets |
|
| 4 | - * |
|
| 5 | - * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | - * |
|
| 7 | - * This source file is subject to the MIT license that is bundled |
|
| 8 | - * with this source code in the file LICENSE. |
|
| 9 | - */ |
|
| 3 | + * Async sockets |
|
| 4 | + * |
|
| 5 | + * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | + * |
|
| 7 | + * This source file is subject to the MIT license that is bundled |
|
| 8 | + * with this source code in the file LICENSE. |
|
| 9 | + */ |
|
| 10 | 10 | namespace AsyncSockets\Socket; |
| 11 | 11 | |
| 12 | 12 | use AsyncSockets\Frame\FramePickerInterface; |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | private function isDescriptorActive(OperationMetadata $descriptor) |
| 54 | 54 | { |
| 55 | 55 | $meta = $descriptor->getMetadata(); |
| 56 | - return !$meta[ RequestExecutorInterface::META_REQUEST_COMPLETE ] && |
|
| 56 | + return !$meta[RequestExecutorInterface::META_REQUEST_COMPLETE] && |
|
| 57 | 57 | $descriptor->isRunning() && |
| 58 | 58 | !$descriptor->isPostponed(); |
| 59 | 59 | } |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Async sockets |
|
| 4 | - * |
|
| 5 | - * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | - * |
|
| 7 | - * This source file is subject to the MIT license that is bundled |
|
| 8 | - * with this source code in the file LICENSE. |
|
| 9 | - */ |
|
| 3 | + * Async sockets |
|
| 4 | + * |
|
| 5 | + * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | + * |
|
| 7 | + * This source file is subject to the MIT license that is bundled |
|
| 8 | + * with this source code in the file LICENSE. |
|
| 9 | + */ |
|
| 10 | 10 | namespace AsyncSockets\Socket; |
| 11 | 11 | |
| 12 | 12 | use AsyncSockets\Frame\FramePickerInterface; |
@@ -41,8 +41,7 @@ discard block |
||
| 41 | 41 | { |
| 42 | 42 | $meta = $operation->getMetadata(); |
| 43 | 43 | return !$this->hasConnected($operation) ? |
| 44 | - $meta[ RequestExecutorInterface::META_CONNECTION_TIMEOUT ] : |
|
| 45 | - $meta[ RequestExecutorInterface::META_IO_TIMEOUT ]; |
|
| 44 | + $meta[RequestExecutorInterface::META_CONNECTION_TIMEOUT] : $meta[RequestExecutorInterface::META_IO_TIMEOUT]; |
|
| 46 | 45 | } |
| 47 | 46 | |
| 48 | 47 | /** |
@@ -56,8 +55,7 @@ discard block |
||
| 56 | 55 | { |
| 57 | 56 | $meta = $operation->getMetadata(); |
| 58 | 57 | return !$this->hasConnected($operation) ? |
| 59 | - $meta[ RequestExecutorInterface::META_CONNECTION_START_TIME ] : |
|
| 60 | - $meta[ RequestExecutorInterface::META_LAST_IO_START_TIME ]; |
|
| 58 | + $meta[RequestExecutorInterface::META_CONNECTION_START_TIME] : $meta[RequestExecutorInterface::META_LAST_IO_START_TIME]; |
|
| 61 | 59 | } |
| 62 | 60 | |
| 63 | 61 | /** |
@@ -74,7 +72,7 @@ discard block |
||
| 74 | 72 | $meta = $operationMetadata->getMetadata(); |
| 75 | 73 | $table = [ |
| 76 | 74 | RequestExecutorInterface::META_CONNECTION_START_TIME => |
| 77 | - $meta[ RequestExecutorInterface::META_CONNECTION_START_TIME ] === null, |
|
| 75 | + $meta[RequestExecutorInterface::META_CONNECTION_START_TIME] === null, |
|
| 78 | 76 | |
| 79 | 77 | RequestExecutorInterface::META_CONNECTION_FINISH_TIME => |
| 80 | 78 | $meta[RequestExecutorInterface::META_CONNECTION_FINISH_TIME] === null, |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Async sockets |
|
| 4 | - * |
|
| 5 | - * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | - * |
|
| 7 | - * This source file is subject to the MIT license that is bundled |
|
| 8 | - * with this source code in the file LICENSE. |
|
| 9 | - */ |
|
| 3 | + * Async sockets |
|
| 4 | + * |
|
| 5 | + * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | + * |
|
| 7 | + * This source file is subject to the MIT license that is bundled |
|
| 8 | + * with this source code in the file LICENSE. |
|
| 9 | + */ |
|
| 10 | 10 | namespace AsyncSockets\Socket; |
| 11 | 11 | |
| 12 | 12 | use AsyncSockets\Frame\FramePickerInterface; |
@@ -137,7 +137,7 @@ |
||
| 137 | 137 | * @param OperationMetadata $operation Operation object |
| 138 | 138 | * @param double $microTime Current time with microseconds |
| 139 | 139 | * |
| 140 | - * @return double|null |
|
| 140 | + * @return double |
|
| 141 | 141 | */ |
| 142 | 142 | private function getSingleSocketTimeout(OperationMetadata $operation, $microTime) |
| 143 | 143 | { |
@@ -127,8 +127,7 @@ discard block |
||
| 127 | 127 | private function getMinTimeout($newValue, $oldValue) |
| 128 | 128 | { |
| 129 | 129 | return (($newValue > 0 && $newValue < $oldValue) || $oldValue === null) ? |
| 130 | - $newValue : |
|
| 131 | - $oldValue; |
|
| 130 | + $newValue : $oldValue; |
|
| 132 | 131 | } |
| 133 | 132 | |
| 134 | 133 | /** |
@@ -149,8 +148,7 @@ discard block |
||
| 149 | 148 | } |
| 150 | 149 | |
| 151 | 150 | $result = $lastOperationTime === null ? |
| 152 | - $desiredTimeout : |
|
| 153 | - $desiredTimeout - ($microTime - $lastOperationTime); |
|
| 151 | + $desiredTimeout : $desiredTimeout - ($microTime - $lastOperationTime); |
|
| 154 | 152 | |
| 155 | 153 | return $result >= 0 ? $result : 0; |
| 156 | 154 | } |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Async sockets |
|
| 4 | - * |
|
| 5 | - * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | - * |
|
| 7 | - * This source file is subject to the MIT license that is bundled |
|
| 8 | - * with this source code in the file LICENSE. |
|
| 9 | - */ |
|
| 3 | + * Async sockets |
|
| 4 | + * |
|
| 5 | + * @copyright Copyright (c) 2015-2016, Efimov Evgenij <[email protected]> |
|
| 6 | + * |
|
| 7 | + * This source file is subject to the MIT license that is bundled |
|
| 8 | + * with this source code in the file LICENSE. |
|
| 9 | + */ |
|
| 10 | 10 | namespace AsyncSockets\Socket; |
| 11 | 11 | |
| 12 | 12 | use AsyncSockets\Frame\FramePickerInterface; |