|
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
|
|
|
|
|
11
|
|
|
namespace AsyncSockets\Event; |
|
12
|
|
|
|
|
13
|
|
|
use AsyncSockets\RequestExecutor\RequestExecutorInterface; |
|
14
|
|
|
use AsyncSockets\Socket\SocketInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class Event |
|
18
|
|
|
* |
|
19
|
|
|
* @api |
|
20
|
|
|
*/ |
|
21
|
|
|
class Event extends AbstractEvent |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Socket linked to this event |
|
25
|
|
|
* |
|
26
|
|
|
* @var SocketInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $socket; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* User data for this event |
|
32
|
|
|
* |
|
33
|
|
|
* @var mixed |
|
34
|
|
|
*/ |
|
35
|
|
|
private $context; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Request executor |
|
39
|
|
|
* |
|
40
|
|
|
* @var RequestExecutorInterface |
|
41
|
|
|
*/ |
|
42
|
|
|
private $executor; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* This event type |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
private $type; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Flag to stop this socket request |
|
53
|
|
|
* |
|
54
|
|
|
* @var bool |
|
55
|
|
|
*/ |
|
56
|
|
|
private $isCancelled; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Constructor |
|
60
|
|
|
* |
|
61
|
|
|
* @param RequestExecutorInterface $executor Request executor object |
|
62
|
|
|
* @param SocketInterface $socket Socket for this request |
|
63
|
|
|
* @param mixed $context Any optional user data for event |
|
64
|
|
|
* @param string $type One of EventType::* constants |
|
65
|
|
|
*/ |
|
66
|
206 |
|
public function __construct(RequestExecutorInterface $executor, SocketInterface $socket, $context, $type) |
|
67
|
|
|
{ |
|
68
|
206 |
|
$this->executor = $executor; |
|
69
|
206 |
|
$this->socket = $socket; |
|
70
|
206 |
|
$this->context = $context; |
|
71
|
206 |
|
$this->type = $type; |
|
72
|
206 |
|
$this->isCancelled = false; |
|
73
|
206 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Return associated socket |
|
77
|
|
|
* |
|
78
|
|
|
* @return SocketInterface |
|
79
|
|
|
*/ |
|
80
|
19 |
|
public function getSocket() |
|
81
|
|
|
{ |
|
82
|
19 |
|
return $this->socket; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Return user specified context |
|
87
|
|
|
* |
|
88
|
|
|
* @return mixed |
|
89
|
|
|
*/ |
|
90
|
25 |
|
public function getContext() |
|
91
|
|
|
{ |
|
92
|
25 |
|
return $this->context; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Return RequestExecutor |
|
97
|
|
|
* |
|
98
|
|
|
* @return RequestExecutorInterface |
|
99
|
|
|
*/ |
|
100
|
24 |
|
public function getExecutor() |
|
101
|
|
|
{ |
|
102
|
24 |
|
return $this->executor; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Return type of this event |
|
107
|
|
|
* |
|
108
|
|
|
* @return string One of EventType::* consts |
|
109
|
|
|
*/ |
|
110
|
148 |
|
public function getType() |
|
111
|
|
|
{ |
|
112
|
148 |
|
return $this->type; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Return flag whether this socket operation is cancelled |
|
117
|
|
|
* |
|
118
|
|
|
* @return boolean |
|
119
|
|
|
*/ |
|
120
|
132 |
|
public function isOperationCancelled() |
|
121
|
|
|
{ |
|
122
|
132 |
|
return $this->isCancelled; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Sets cancel this operation flag |
|
127
|
|
|
* |
|
128
|
|
|
* @param boolean $isCancelled Cancel flag |
|
129
|
|
|
* |
|
130
|
|
|
* @return void |
|
131
|
|
|
*/ |
|
132
|
12 |
|
public function cancelThisOperation($isCancelled = true) |
|
133
|
|
|
{ |
|
134
|
12 |
|
$this->isCancelled = $isCancelled; |
|
135
|
12 |
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|