1 | <?php |
||
18 | class TimeoutEvent extends Event |
||
19 | { |
||
20 | /** |
||
21 | * Timeout during connection |
||
22 | */ |
||
23 | const DURING_CONNECTION = 'connection'; |
||
24 | |||
25 | /** |
||
26 | * Timeout during I/O operation |
||
27 | */ |
||
28 | const DURING_IO = 'io'; |
||
29 | |||
30 | /** |
||
31 | * Stage when occured timeout |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | private $when; |
||
36 | |||
37 | /** |
||
38 | * Flag whether we can enable one more I/O attempt for this socket |
||
39 | * |
||
40 | * @var bool |
||
41 | */ |
||
42 | private $isNextAttemptEnabled = false; |
||
43 | |||
44 | /** |
||
45 | * TimeoutEvent constructor. |
||
46 | * |
||
47 | * @param RequestExecutorInterface $executor Request executor object |
||
48 | * @param SocketInterface $socket Socket for this request |
||
49 | * @param mixed $context Any optional user data for event |
||
50 | * @param string $when One of DURING_* constants |
||
51 | */ |
||
52 | 25 | public function __construct(RequestExecutorInterface $executor, SocketInterface $socket, $context, $when) |
|
57 | |||
58 | /** |
||
59 | * Return stage when timeout occurred |
||
60 | * |
||
61 | * @return string one of DURING_* consts |
||
62 | */ |
||
63 | 3 | public function when() |
|
64 | { |
||
65 | 3 | return $this->when; |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Mark operation for try-again |
||
70 | * |
||
71 | * @return void |
||
72 | */ |
||
73 | 3 | public function enableOneMoreAttempt() |
|
74 | { |
||
75 | 3 | $this->isNextAttemptEnabled = true; |
|
76 | 3 | } |
|
77 | |||
78 | /** |
||
79 | * Return true if we can try to connect / I/O once again |
||
80 | * |
||
81 | * @return boolean |
||
82 | */ |
||
83 | 14 | public function isNextAttemptEnabled() |
|
87 | } |
||
88 |