| 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
28 namespace AsyncSocketIo {
30 public struct SocketPollOperationInfo {
32 Socket sock;
33
35 AbstractPollOperation spop;
36
38 date to = AsyncSocketIoController::DefaultIoOperationTimeout;
39
41 *hash<auto> other;
42};
43
45 public struct SocketPollResultInfo {
47 AbstractPollOperation spop;
48
50 *bool canceled;
51
53 *hash<ExceptionInfo> ex;
54
56 *hash<auto> other;
57};
58
60 class AsyncSocketIoController : public LoggerWrapper {
61
62 public:
64 const PollEventMap = ...;
65
66
68 const DefaultIoOperationTimeout = 30s;
69
70 protected:
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
92 public:
93
94 private:
96 File sem_write;
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
116 public:
117
119 constructor(bool autostop, *LoggerInterface logger) ;
120
121
123 constructor(*LoggerInterface logger) ;
124
125
127 destructor();
128
129
131 hash<auto> getInfo();
132
133
135 setAutostop(bool autostop = True);
136
137
139 bool getAutostop();
140
141
143
145 start();
146
147
149 stop();
150
151
153 stopClear();
154
155
157 waitStop();
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
215 protected:
216 constructorInit();
217 public:
218
219
221 protected:
222 cancelIntern(string uh);
223 public:
224
225
226 protected:
227 startIntern();
228 public:
229
230
231 protected:
232 int stopIntern();
233 public:
234
235
236 protected:
237 ioThread();
238 public:
239
240
241 protected:
242 *bool processCommands();
243 public:
244
245
246 protected:
247 doCancelIntern(hash<PollInfo> cinfo);
248 public:
249
250
251 protected:
252 sendCmd(string cmd);
253 public:
254
255};
256};
257
258// private symbols
259 namespace 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}
AsyncSocketIo::AsyncSocketIoController
Class for controlling async socket I/O.
Definition AsyncSocketIoController.qc.dox.h:60
AsyncSocketIo::AsyncSocketIoController::m
Mutex m()
Lock for atomic actions.
AsyncSocketIo::AsyncSocketIoController::submit
Queue submit(hash< SocketPollOperationInfo > info, *bool replace)
Submits a socket operation to be performed and returns a Queue where the results will be returned.
AsyncSocketIo::AsyncSocketIoController::cmdq
Queue cmdq()
I/O thread command queue.
AsyncSocketIo::AsyncSocketIoController::mcnt
Counter mcnt()
I/O thread counter.
AsyncSocketIo::AsyncSocketIoController::tid
int tid
I/O thread TID.
Definition AsyncSocketIoController.qc.dox.h:78
AsyncSocketIo::AsyncSocketIoController::constructorInit
constructorInit()
Common constructor code.
AsyncSocketIo::AsyncSocketIoController::IO_ADD
const IO_ADD
I/O thread command: add.
Definition AsyncSocketIoController.qc.dox.h:84
AsyncSocketIo::AsyncSocketIoController::IO_QUIT
const IO_QUIT
I/O thread command: quit.
Definition AsyncSocketIoController.qc.dox.h:90
AsyncSocketIo::AsyncSocketIoController::constructor
constructor(*LoggerInterface logger)
Creates the object.
AsyncSocketIo::AsyncSocketIoController::running
bool running()
Returns True if the I/O thread is running.
AsyncSocketIo::AsyncSocketIoController::cancelIntern
cancelIntern(string uh)
Cancels an operation in progress and sends an appropriate message on the result queue.
AsyncSocketIo::AsyncSocketIoController::getAutostop
bool getAutostop()
Get autostop flag.
AsyncSocketIo::AsyncSocketIoController::sem_read
ReadOnlyFile sem_read
File to read in the I/O thread.
Definition AsyncSocketIoController.qc.dox.h:99
AsyncSocketIo::AsyncSocketIoController::DefaultIoOperationTimeout
const DefaultIoOperationTimeout
Default I/O timeout duration.
Definition AsyncSocketIoController.qc.dox.h:68
AsyncSocketIo::AsyncSocketIoController::stopClear
stopClear()
Stops monitoring and clears all connections.
AsyncSocketIo::AsyncSocketIoController::sem_write
File sem_write
File to signal the I/O thread.
Definition AsyncSocketIoController.qc.dox.h:96
AsyncSocketIo::AsyncSocketIoController::sem_info
hash< SocketPollInfo > sem_info
Semaphore descriptor info.
Definition AsyncSocketIoController.qc.dox.h:102
AsyncSocketIo::AsyncSocketIoController::getInfo
hash< auto > getInfo()
Returns information about the object.
AsyncSocketIo::AsyncSocketIoController::PollEventMap
const PollEventMap
Polling event map.
Definition AsyncSocketIoController.qc.dox.h:64
AsyncSocketIo::AsyncSocketIoController::destructor
destructor()
Stops the monitoring thread and destroys the object.
AsyncSocketIo::AsyncSocketIoController::cancel
bool cancel(Socket sock)
Cancels any operation in progress for the given Socket.
AsyncSocketIo::AsyncSocketIoController::start
start()
Starts monitoring.
AsyncSocketIo::AsyncSocketIoController::autostop
bool autostop
Stop monitoring thread when the last operation is complete.
Definition AsyncSocketIoController.qc.dox.h:81
AsyncSocketIo::AsyncSocketIoController::cache
hash< string, hash< PollInfo > > cache
Socket cache; unique hash -> poll info.
Definition AsyncSocketIoController.qc.dox.h:75
AsyncSocketIo::AsyncSocketIoController::constructor
constructor(bool autostop, *LoggerInterface logger)
For listener sockets.
AsyncSocketIo::AsyncSocketIoController::stop
stop()
Stops monitoring.
AsyncSocketIo::AsyncSocketIoController::setAutostop
setAutostop(bool autostop=True)
Set autostop flag.
AsyncSocketIo::AsyncSocketIoController::IO_CANCEL
const IO_CANCEL
I/O thread command: cancel.
Definition AsyncSocketIoController.qc.dox.h:87
AsyncSocketIo::AsyncSocketIoController::cancelEx
cancelEx(Socket sock)
Cancels any operation in progress for the given Socket.
AsyncSocketIo::AsyncSocketIoController::waitStop
waitStop()
Waits for the monitoring thread to stop if it's running.
AsyncSocketIo::AsyncSocketIoController::cancel_cond_map
hash< string, Condition > cancel_cond_map
Cancel operation waiting Condition; socket unique key -> Condition.
Definition AsyncSocketIoController.qc.dox.h:111
AsyncSocketIo::AsyncSocketIoController::exec
hash< SocketPollResultInfo > exec(hash< SocketPollOperationInfo > info, *bool replace)
Executes a socket operation asynchronously and waits for the results.
AsyncSocketIo
The AsyncSocketIo namespace.
Definition AsyncSocketIo.qm.dox.h:51
Priv
AsyncSocketIo::SocketPollOperationInfo
Socket polling operation info hash.
Definition AsyncSocketIoController.qc.dox.h:30
AsyncSocketIo::SocketPollOperationInfo::to
date to
I/O timeout.
Definition AsyncSocketIoController.qc.dox.h:38
AsyncSocketIo::SocketPollOperationInfo::other
*hash< auto > other
Free-form data to be returned when the operation completes.
Definition AsyncSocketIoController.qc.dox.h:41
AsyncSocketIo::SocketPollOperationInfo::spop
AbstractPollOperation spop
Poll operation.
Definition AsyncSocketIoController.qc.dox.h:35
AsyncSocketIo::SocketPollOperationInfo::sock
Socket sock
Socket object.
Definition AsyncSocketIoController.qc.dox.h:32
AsyncSocketIo::SocketPollResultInfo
Socket poll result.
Definition AsyncSocketIoController.qc.dox.h:45
AsyncSocketIo::SocketPollResultInfo::other
*hash< auto > other
Free-form data provided when the operation was submitted.
Definition AsyncSocketIoController.qc.dox.h:56
AsyncSocketIo::SocketPollResultInfo::spop
AbstractPollOperation spop
The poll operation that completed.
Definition AsyncSocketIoController.qc.dox.h:47
AsyncSocketIo::SocketPollResultInfo::canceled
*bool canceled
If the operation was canceled.
Definition AsyncSocketIoController.qc.dox.h:50
AsyncSocketIo::SocketPollResultInfo::ex
*hash< ExceptionInfo > ex
Any exception raised while executing the operation.
Definition AsyncSocketIoController.qc.dox.h:53