1 | <?php |
||
21 | class StreamedClientIo extends AbstractClientIo |
||
22 | { |
||
23 | /** |
||
24 | * Read attempts count |
||
25 | */ |
||
26 | const READ_ATTEMPTS = 2; |
||
27 | |||
28 | /** |
||
29 | * Amount of read attempts |
||
30 | * |
||
31 | * @var int |
||
32 | */ |
||
33 | private $readAttempts = self::READ_ATTEMPTS; |
||
34 | |||
35 | /** |
||
36 | * Remote socket address |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | private $remoteAddress; |
||
41 | |||
42 | /** {@inheritdoc} */ |
||
43 | 27 | protected function readRawDataIntoPicker(FramePickerInterface $picker, $isOutOfBand) |
|
47 | |||
48 | /** {@inheritdoc} */ |
||
49 | 7 | protected function writeRawData($data, $isOutOfBand) |
|
62 | |||
63 | /** |
||
64 | * Verifies that send operation completed successfully |
||
65 | * |
||
66 | * @param string $data Data for remote side |
||
67 | * @param int|bool $sendResult Return value from send function |
||
68 | * |
||
69 | * @return void |
||
70 | * @throws NetworkSocketException |
||
71 | */ |
||
72 | 7 | private function verifySendResult($data, $sendResult) |
|
85 | |||
86 | /** {@inheritdoc} */ |
||
87 | 40 | public function isConnected() |
|
91 | |||
92 | /** {@inheritdoc} */ |
||
93 | 26 | protected function getRemoteAddress() |
|
104 | |||
105 | /** {@inheritdoc} */ |
||
106 | 3 | protected function canReachFrame() |
|
110 | |||
111 | /** |
||
112 | * Read OOB data from socket |
||
113 | * |
||
114 | * @param FramePickerInterface $picker |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | 1 | private function readOobData(FramePickerInterface $picker) |
|
128 | |||
129 | /** |
||
130 | * Read regular data |
||
131 | * |
||
132 | * @param FramePickerInterface $picker Picker to read data into |
||
133 | * |
||
134 | * @return string |
||
135 | */ |
||
136 | 26 | private function readRegularData(FramePickerInterface $picker) |
|
165 | |||
166 | /** |
||
167 | * Return first byte from socket buffer |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | 26 | private function getDataInSocket() |
|
175 | |||
176 | /** |
||
177 | * Checks whether data read from stream buffer can be filled later |
||
178 | * |
||
179 | * @param string $data Read data |
||
180 | * |
||
181 | * @return bool |
||
182 | */ |
||
183 | 25 | private function isReadDataActuallyEmpty($data) |
|
193 | |||
194 | /** |
||
195 | * Calculate attempts value |
||
196 | * |
||
197 | * @param array $context Read context |
||
198 | * @param int $currentAttempts Current attempts counter |
||
199 | * |
||
200 | * @return int |
||
201 | */ |
||
202 | 25 | private function resolveReadAttempts(array $context, $currentAttempts) |
|
210 | |||
211 | /** |
||
212 | * Write out-of-band data |
||
213 | * |
||
214 | * @param resource $socket Socket resource |
||
215 | * @param string $data Data to write |
||
216 | * |
||
217 | * @return int Amount of written bytes |
||
218 | */ |
||
219 | 2 | private function writeOobData($socket, $data) |
|
236 | |||
237 | /** |
||
238 | * Return remote address if we connected or false otherwise |
||
239 | * |
||
240 | * @return string|null |
||
241 | */ |
||
242 | 40 | private function resolveRemoteAddress() |
|
248 | } |
||
249 |