| @@ 266-288 (lines=23) @@ | ||
| 263 | * |
|
| 264 | * @internal |
|
| 265 | */ |
|
| 266 | public function handleRead() |
|
| 267 | { |
|
| 268 | $length = $this->bufferSize; |
|
| 269 | $ret = fread($this->resource, $length); |
|
| 270 | ||
| 271 | if ($ret === false) |
|
| 272 | { |
|
| 273 | $this->emit('error', [ $this, new ReadException('Error occurred while reading from the stream resource.') ]); |
|
| 274 | return; |
|
| 275 | } |
|
| 276 | ||
| 277 | if ($ret !== '') |
|
| 278 | { |
|
| 279 | $this->emit('data', [ $this, $ret ]); |
|
| 280 | ||
| 281 | if (strlen($ret) < $length) |
|
| 282 | { |
|
| 283 | $this->loop->removeReadStream($this->resource); |
|
| 284 | $this->reading = false; |
|
| 285 | $this->emit('end', [ $this ]); |
|
| 286 | } |
|
| 287 | } |
|
| 288 | } |
|
| 289 | ||
| 290 | /** |
|
| 291 | * Handle close. |
|
| @@ 153-175 (lines=23) @@ | ||
| 150 | * |
|
| 151 | * @internal |
|
| 152 | */ |
|
| 153 | public function handleRead() |
|
| 154 | { |
|
| 155 | $length = $this->bufferSize; |
|
| 156 | $ret = fread($this->resource, $length); |
|
| 157 | ||
| 158 | if ($ret === false) |
|
| 159 | { |
|
| 160 | $this->emit('error', [ $this, new ReadException('Error occurred while reading from the stream resource.') ]); |
|
| 161 | return; |
|
| 162 | } |
|
| 163 | ||
| 164 | if ($ret !== '') |
|
| 165 | { |
|
| 166 | $this->emit('data', [ $this, $ret ]); |
|
| 167 | ||
| 168 | if (strlen($ret) < $length) |
|
| 169 | { |
|
| 170 | $this->loop->removeReadStream($this->resource); |
|
| 171 | $this->reading = false; |
|
| 172 | $this->emit('end', [ $this ]); |
|
| 173 | } |
|
| 174 | } |
|
| 175 | } |
|
| 176 | ||
| 177 | /** |
|
| 178 | * Get function that should be invoked on read event. |
|