1 | <?php |
||
23 | class ConnectionContext |
||
24 | { |
||
25 | /** |
||
26 | * The greeting munin expects |
||
27 | */ |
||
28 | const GREETING = '# munin node at %s'; |
||
29 | |||
30 | /** |
||
31 | * The timeout after which we disconnection for no data transmission |
||
32 | */ |
||
33 | const CONNECTION_TIMEOUT = 60; |
||
34 | |||
35 | /** |
||
36 | * New line |
||
37 | */ |
||
38 | const NEW_LINE = "\n"; |
||
39 | |||
40 | /** |
||
41 | * @var DuplexStreamInterface |
||
42 | */ |
||
43 | private $conn; |
||
44 | |||
45 | /** |
||
46 | * @var Node |
||
47 | */ |
||
48 | private $node; |
||
49 | |||
50 | /** |
||
51 | * @var TimerInterface |
||
52 | */ |
||
53 | private $timeoutTimer; |
||
54 | |||
55 | /** |
||
56 | * @var LoopInterface |
||
57 | */ |
||
58 | private $loop; |
||
59 | |||
60 | /** |
||
61 | * @param DuplexStreamInterface $conn |
||
62 | * @param Node $node |
||
63 | */ |
||
64 | 5 | public function __construct(DuplexStreamInterface $conn, Node $node) |
|
82 | |||
83 | /** |
||
84 | * Write data to the connection |
||
85 | * |
||
86 | * @param string $data |
||
87 | */ |
||
88 | 5 | protected function write(string $data) |
|
95 | |||
96 | /** |
||
97 | * Clear the timeout, close the connection, and tell node the client disconnected |
||
98 | */ |
||
99 | 1 | protected function close() |
|
104 | |||
105 | /** |
||
106 | * Set a timeout that disconnects the client when it's idle for to long |
||
107 | */ |
||
108 | 5 | protected function setTimeout() |
|
117 | |||
118 | /** |
||
119 | * Clear the timeout if it's set |
||
120 | */ |
||
121 | 5 | protected function clearTimeout() |
|
128 | |||
129 | /** |
||
130 | * Handle a command call from the clients side |
||
131 | * |
||
132 | * @param string $data |
||
133 | */ |
||
134 | 1 | public function onData(string $data) |
|
165 | |||
166 | /** |
||
167 | * Close connection |
||
168 | */ |
||
169 | 1 | public function quit() |
|
174 | |||
175 | /** |
||
176 | * Close connection |
||
177 | */ |
||
178 | public function onClose() |
||
182 | |||
183 | /** |
||
184 | * @param string $message |
||
185 | */ |
||
186 | 5 | protected function log(string $message) |
|
190 | } |
||
191 |