Qore AsyncSocketIo Module Reference 2.0
Loading...
Searching...
No Matches
AsyncSocketIoController.qc.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
2// Qore AsyncSocketIoController class definition
3
4/* AsyncSocketIoController.qc Copyright 2016 - 2024 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
26
28namespace AsyncSocketIo {
30public hashdecl SocketPollOperationInfo {
32 Socket sock;
33
35 AbstractPollOperation spop;
36
39
41 *hash<auto> other;
42};
43
45public hashdecl SocketPollResultInfo {
47 AbstractPollOperation spop;
48
50 *bool canceled;
51
53 *hash<ExceptionInfo> ex;
54
56 *hash<auto> other;
57};
58
60class AsyncSocketIoController : public LoggerWrapper {
61
62public:
64 const PollEventMap = ...;
65
66
69
70protected:
72 Mutex m();
73
75 hash<string, hash<PollInfo>> cache;
76
78 int tid;
79
81 bool autostop = True;
82
84 const IO_ADD = "add";
85
87 const IO_CANCEL = "cancel";
88
90 const IO_QUIT = "quit";
91
92public:
93
94private:
97
99 ReadOnlyFile sem_read;
100
102 hash<SocketPollInfo> sem_info;
103
105 Counter mcnt();
106
108 Queue cmdq();
109
111 hash<string, Condition> cancel_cond_map;
112
114
115
116public:
117
119 constructor(bool autostop, *LoggerInterface logger) ;
120
121
123 constructor(*LoggerInterface logger) ;
124
125
128
129
131 hash<auto> getInfo();
132
133
135 setAutostop(bool autostop = True);
136
137
140
141
143
146
147
150
151
154
155
158
159
161 bool running();
162
163
165
173 Queue submit(hash<SocketPollOperationInfo> info, *bool replace);
174
175
177
185 hash<SocketPollResultInfo> exec(hash<SocketPollOperationInfo> info, *bool replace);
186
187
189
197 bool cancel(Socket sock);
198
199
201
211 cancelEx(Socket sock);
212
213
215protected:
217public:
218
219
221protected:
222 cancelIntern(string uh);
223public:
224
225
226protected:
227 startIntern();
228public:
229
230
231protected:
232 int stopIntern();
233public:
234
235
236protected:
237 ioThread();
238public:
239
240
241protected:
242 *bool processCommands();
243public:
244
245
246protected:
247 doCancelIntern(hash<PollInfo> cinfo);
248public:
249
250
251protected:
252 sendCmd(string cmd);
253public:
254
255};
256};
257
258// private symbols
259namespace Priv {
260// internal poll info
261hashdecl PollInfo {
263 date timeout_date;
264
266 Socket sock;
267
269 AbstractPollOperation spop;
270
272 date to = AsyncSocketIoController::DefaultIoOperationTimeout;
273
275 *hash<auto> other;
276
278 Queue q();
279}
280}
Class for controlling async socket I/O.
Definition AsyncSocketIoController.qc.dox.h:60
Mutex m()
Lock for atomic actions.
Queue submit(hash< SocketPollOperationInfo > info, *bool replace)
Submits a socket operation to be performed and returns a Queue where the results will be returned.
Queue cmdq()
I/O thread command queue.
Counter mcnt()
I/O thread counter.
int tid
I/O thread TID.
Definition AsyncSocketIoController.qc.dox.h:78
constructorInit()
Common constructor code.
const IO_ADD
I/O thread command: add.
Definition AsyncSocketIoController.qc.dox.h:84
const IO_QUIT
I/O thread command: quit.
Definition AsyncSocketIoController.qc.dox.h:90
constructor(*LoggerInterface logger)
Creates the object.
bool running()
Returns True if the I/O thread is running.
cancelIntern(string uh)
Cancels an operation in progress and sends an appropriate message on the result queue.
bool getAutostop()
Get autostop flag.
ReadOnlyFile sem_read
File to read in the I/O thread.
Definition AsyncSocketIoController.qc.dox.h:99
const DefaultIoOperationTimeout
Default I/O timeout duration.
Definition AsyncSocketIoController.qc.dox.h:68
stopClear()
Stops monitoring and clears all connections.
File sem_write
File to signal the I/O thread.
Definition AsyncSocketIoController.qc.dox.h:96
hash< SocketPollInfo > sem_info
Semaphore descriptor info.
Definition AsyncSocketIoController.qc.dox.h:102
hash< auto > getInfo()
Returns information about the object.
const PollEventMap
Polling event map.
Definition AsyncSocketIoController.qc.dox.h:64
destructor()
Stops the monitoring thread and destroys the object.
bool cancel(Socket sock)
Cancels any operation in progress for the given Socket.
bool autostop
Stop monitoring thread when the last operation is complete.
Definition AsyncSocketIoController.qc.dox.h:81
hash< string, hash< PollInfo > > cache
Socket cache; unique hash -> poll info.
Definition AsyncSocketIoController.qc.dox.h:75
constructor(bool autostop, *LoggerInterface logger)
For listener sockets.
setAutostop(bool autostop=True)
Set autostop flag.
const IO_CANCEL
I/O thread command: cancel.
Definition AsyncSocketIoController.qc.dox.h:87
cancelEx(Socket sock)
Cancels any operation in progress for the given Socket.
waitStop()
Waits for the monitoring thread to stop if it's running.
hash< string, Condition > cancel_cond_map
Cancel operation waiting Condition; socket unique key -> Condition.
Definition AsyncSocketIoController.qc.dox.h:111
hash< SocketPollResultInfo > exec(hash< SocketPollOperationInfo > info, *bool replace)
Executes a socket operation asynchronously and waits for the results.
The AsyncSocketIo namespace.
Definition AsyncSocketIo.qm.dox.h:51
Socket polling operation info hash.
Definition AsyncSocketIoController.qc.dox.h:30
date to
I/O timeout.
Definition AsyncSocketIoController.qc.dox.h:38
*hash< auto > other
Free-form data to be returned when the operation completes.
Definition AsyncSocketIoController.qc.dox.h:41
AbstractPollOperation spop
Poll operation.
Definition AsyncSocketIoController.qc.dox.h:35
Socket sock
Socket object.
Definition AsyncSocketIoController.qc.dox.h:32
Socket poll result.
Definition AsyncSocketIoController.qc.dox.h:45
*hash< auto > other
Free-form data provided when the operation was submitted.
Definition AsyncSocketIoController.qc.dox.h:56
AbstractPollOperation spop
The poll operation that completed.
Definition AsyncSocketIoController.qc.dox.h:47
*bool canceled
If the operation was canceled.
Definition AsyncSocketIoController.qc.dox.h:50
*hash< ExceptionInfo > ex
Any exception raised while executing the operation.
Definition AsyncSocketIoController.qc.dox.h:53