1 | <?php |
||
17 | class StreamedClientIo extends AbstractClientIo |
||
18 | { |
||
19 | /** |
||
20 | * Read attempts count |
||
21 | */ |
||
22 | const READ_ATTEMPTS = 2; |
||
23 | |||
24 | /** |
||
25 | * Amount of read attempts |
||
26 | * |
||
27 | * @var int |
||
28 | */ |
||
29 | private $readAttempts = self::READ_ATTEMPTS; |
||
30 | |||
31 | /** |
||
32 | * Remote socket address |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | private $remoteAddress; |
||
37 | |||
38 | /** {@inheritdoc} */ |
||
39 | 26 | protected function readRawDataIntoPicker(FramePickerInterface $picker, $isOutOfBand) |
|
43 | |||
44 | /** |
||
45 | * Read OOB data from socket |
||
46 | * |
||
47 | * @param FramePickerInterface $picker |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | 1 | private function readOobData(FramePickerInterface $picker) |
|
61 | |||
62 | /** |
||
63 | * Read regular data |
||
64 | * |
||
65 | * @param FramePickerInterface $picker Picker to read data into |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | 25 | private function readRegularData(FramePickerInterface $picker) |
|
92 | |||
93 | /** |
||
94 | * Calculate attempts value |
||
95 | * |
||
96 | * @param array $context Read context |
||
97 | * @param int $currentAttempts Current attempts counter |
||
98 | * |
||
99 | * @return int |
||
100 | */ |
||
101 | 24 | private function resolveReadAttempts(array $context, $currentAttempts) |
|
109 | |||
110 | /** {@inheritdoc} */ |
||
111 | 5 | protected function writeRawData($data, $isOutOfBand) |
|
129 | |||
130 | /** {@inheritdoc} */ |
||
131 | 37 | protected function isConnected() |
|
135 | |||
136 | /** {@inheritdoc} */ |
||
137 | 25 | protected function getRemoteAddress() |
|
145 | |||
146 | /** |
||
147 | * Checks whether data read from stream buffer can be filled later |
||
148 | * |
||
149 | * @param string $data Read data |
||
150 | * |
||
151 | * @return bool |
||
152 | */ |
||
153 | 24 | private function isReadDataActuallyEmpty($data) |
|
163 | |||
164 | /** {@inheritdoc} */ |
||
165 | 2 | protected function canReachFrame() |
|
169 | |||
170 | /** |
||
171 | * Return first byte from socket buffer |
||
172 | * |
||
173 | * @return string |
||
174 | */ |
||
175 | 25 | private function getDataInSocket() |
|
179 | |||
180 | /** |
||
181 | * Return remote address if we connected or false otherwise |
||
182 | * |
||
183 | * @return string|bool |
||
184 | */ |
||
185 | 37 | private function resolveRemoteAddress() |
|
189 | |||
190 | /** |
||
191 | * Write out-of-band data |
||
192 | * |
||
193 | * @param resource $socket Socket resource |
||
194 | * @param string $data Data to write |
||
195 | * |
||
196 | * @return int Amount of written bytes |
||
197 | */ |
||
198 | 1 | private function writeOobData($socket, $data) |
|
214 | } |
||
215 |