1 | <?php |
||
24 | class GuardianStage extends AbstractStage |
||
25 | { |
||
26 | /** |
||
27 | * Maximum socket attempts to execute |
||
28 | */ |
||
29 | const MAX_ATTEMPTS_PER_SOCKET = 25; |
||
30 | |||
31 | /** |
||
32 | * Indexed by RequestDescriptor object hash array of attempts, after which we should kill connection |
||
33 | * |
||
34 | * @var int[] |
||
35 | */ |
||
36 | private $candidates = []; |
||
37 | |||
38 | /** |
||
39 | * Disconnect stage |
||
40 | * |
||
41 | * @var DisconnectStage |
||
42 | */ |
||
43 | private $disconnectStage; |
||
44 | |||
45 | /** |
||
46 | * GuardianStage constructor. |
||
47 | * |
||
48 | * @param RequestExecutorInterface $executor Request executor |
||
49 | * @param EventCaller $eventCaller Event caller |
||
50 | * @param ExecutionContext $executionContext Execution context |
||
51 | * @param DisconnectStage $disconnectStage Disconnect stage |
||
52 | */ |
||
53 | 140 | public function __construct( |
|
62 | |||
63 | /** {@inheritdoc} */ |
||
64 | 80 | public function processStage(array $requestDescriptors) |
|
75 | |||
76 | /** |
||
77 | * Check if this request is alive and managed by client code |
||
78 | * |
||
79 | * @param RequestDescriptor $descriptor Object to test |
||
80 | * |
||
81 | * @return bool True if connection killed, false otherwise |
||
82 | */ |
||
83 | 78 | private function handleDeadConnection(RequestDescriptor $descriptor) |
|
111 | |||
112 | /** |
||
113 | * Check if this socket can be a zombie |
||
114 | * |
||
115 | * @param RequestDescriptor $descriptor Descriptor object |
||
116 | * |
||
117 | * @return bool |
||
118 | */ |
||
119 | 78 | private function isZombieCandidate(RequestDescriptor $descriptor) |
|
133 | |||
134 | /** |
||
135 | * Closes connection, as we suppose it is unmanaged |
||
136 | * |
||
137 | * @param RequestDescriptor $descriptor Descriptor object to kill |
||
138 | * |
||
139 | * @return void |
||
140 | */ |
||
141 | 2 | private function killZombieConnection(RequestDescriptor $descriptor) |
|
152 | |||
153 | /** |
||
154 | * Notify client about unhandled data in socket |
||
155 | * |
||
156 | * @param RequestDescriptor $descriptor Socket operation descriptor |
||
157 | * @param int $attempt Current attempt number from 1 |
||
158 | * @param int $totalAttempts Total attempts |
||
159 | * |
||
160 | * @return void |
||
161 | */ |
||
162 | 4 | private function notifyDataAlert( |
|
184 | } |
||
185 |