|
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\Frame\FramePickerInterface; |
|
14
|
|
|
use AsyncSockets\Operation\OperationInterface; |
|
15
|
|
|
use AsyncSockets\Operation\ReadOperation; |
|
16
|
|
|
use AsyncSockets\Operation\WriteOperation; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class IoEvent |
|
20
|
|
|
* |
|
21
|
|
|
* @api |
|
22
|
|
|
*/ |
|
23
|
|
|
class IoEvent extends Event |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Next operation to perform on socket |
|
27
|
|
|
* |
|
28
|
|
|
* @var OperationInterface|null |
|
29
|
|
|
*/ |
|
30
|
|
|
private $nextOperation; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Return next operation on socket |
|
34
|
|
|
* |
|
35
|
|
|
* @return OperationInterface|null Null means no further operation required |
|
36
|
|
|
*/ |
|
37
|
60 |
|
public function getNextOperation() |
|
38
|
|
|
{ |
|
39
|
60 |
|
return $this->nextOperation; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Mark next operation as read |
|
44
|
|
|
* |
|
45
|
|
|
* @param FramePickerInterface $framePicker Frame picker for reading data |
|
46
|
|
|
* |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
7 |
|
public function nextIsRead(FramePickerInterface $framePicker = null) |
|
50
|
|
|
{ |
|
51
|
7 |
|
$this->nextIs(new ReadOperation($framePicker)); |
|
52
|
7 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Mark next operation as write |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $data Data to write |
|
58
|
|
|
* |
|
59
|
|
|
* @return void |
|
60
|
|
|
*/ |
|
61
|
7 |
|
public function nextIsWrite($data = null) |
|
62
|
|
|
{ |
|
63
|
7 |
|
$this->nextIs(new WriteOperation($data)); |
|
64
|
7 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Changed next operation to given one |
|
68
|
|
|
* |
|
69
|
|
|
* @param OperationInterface $operation Next operation |
|
70
|
|
|
* |
|
71
|
|
|
* @return void |
|
72
|
|
|
*/ |
|
73
|
13 |
|
public function nextIs(OperationInterface $operation) |
|
74
|
|
|
{ |
|
75
|
13 |
|
$this->nextOperation = $operation; |
|
76
|
13 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Mark next operation as not required |
|
80
|
|
|
* |
|
81
|
|
|
* @return void |
|
82
|
|
|
*/ |
|
83
|
7 |
|
public function nextOperationNotRequired() |
|
84
|
|
|
{ |
|
85
|
7 |
|
$this->nextOperation = null; |
|
86
|
7 |
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|