1
|
|
|
<?php |
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
|
|
|
*/ |
10
|
|
|
namespace AsyncSockets\Event; |
11
|
|
|
|
12
|
|
|
use AsyncSockets\Frame\FrameInterface; |
13
|
|
|
use AsyncSockets\Frame\PartialFrame; |
14
|
|
|
use AsyncSockets\RequestExecutor\RequestExecutorInterface; |
15
|
|
|
use AsyncSockets\Socket\SocketInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class ReadEvent |
19
|
|
|
*/ |
20
|
|
|
class ReadEvent extends IoEvent |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Data read from network |
24
|
|
|
* |
25
|
|
|
* @var FrameInterface |
26
|
|
|
*/ |
27
|
|
|
private $frame; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Flag if data are out of band |
31
|
|
|
* |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
private $isOutOfBand; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Constructor |
38
|
|
|
* |
39
|
|
|
* @param RequestExecutorInterface $executor Request executor object |
40
|
|
|
* @param SocketInterface $socket Socket for this request |
41
|
|
|
* @param mixed $context Any optional user data for event |
42
|
|
|
* @param FrameInterface $frame Network data for read operation |
43
|
|
|
* @param bool $isOutOfBand Flag if data are out of band |
44
|
|
|
*/ |
45
|
51 |
|
public function __construct( |
46
|
|
|
RequestExecutorInterface $executor, |
47
|
|
|
SocketInterface $socket, |
48
|
|
|
$context, |
49
|
|
|
FrameInterface $frame, |
50
|
|
|
$isOutOfBand = false |
51
|
|
|
) { |
52
|
51 |
|
parent::__construct($executor, $socket, $context, EventType::READ); |
53
|
51 |
|
$this->frame = $frame; |
54
|
51 |
|
$this->isOutOfBand = $isOutOfBand; |
55
|
51 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Return response frame |
59
|
|
|
* |
60
|
|
|
* @return FrameInterface |
61
|
|
|
*/ |
62
|
9 |
|
public function getFrame() |
63
|
|
|
{ |
64
|
9 |
|
return $this->frame; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Return true, if frame in this event is partial |
69
|
|
|
* |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
3 |
|
public function isPartial() |
73
|
|
|
{ |
74
|
3 |
|
return $this->frame instanceof PartialFrame; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Return true if data are out of band |
79
|
|
|
* |
80
|
|
|
* @return bool |
81
|
|
|
*/ |
82
|
8 |
|
public function isOutOfBand() |
83
|
|
|
{ |
84
|
8 |
|
return $this->isOutOfBand; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|