Loading...
Searching...
No Matches
AsyncSocketIoController.qc.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// Qore AsyncSocketIoController class definition
/* AsyncSocketIoController.qc Copyright 2016 - 2024 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
namespace AsyncSocketIo {
public struct SocketPollOperationInfo {
Socket sock;
AbstractPollOperation spop;
date to = AsyncSocketIoController::DefaultIoOperationTimeout;
*hash<auto> other;
};
public struct SocketPollResultInfo {
AbstractPollOperation spop;
*bool canceled;
*hash<ExceptionInfo> ex;
*hash<auto> other;
};
class AsyncSocketIoController : public LoggerWrapper {
public:
const PollEventMap = ...;
const DefaultIoOperationTimeout = 30s;
protected:
Mutex m();
hash<string, hash<PollInfo>> cache;
int tid;
bool autostop = True;
const IO_ADD = "add";
const IO_CANCEL = "cancel";
const IO_QUIT = "quit";
public:
private:
File sem_write;
ReadOnlyFile sem_read;
hash<SocketPollInfo> sem_info;
Counter mcnt();
Queue cmdq();
hash<string, Condition> cancel_cond_map;
public:
constructor(bool autostop, *LoggerInterface logger) ;
constructor(*LoggerInterface logger) ;
destructor();
hash<auto> getInfo();
setAutostop(bool autostop = True);
bool getAutostop();
start();
stop();
stopClear();
waitStop();
bool running();
Queue submit(hash<SocketPollOperationInfo> info, *bool replace);
hash<SocketPollResultInfo> exec(hash<SocketPollOperationInfo> info, *bool replace);
bool cancel(Socket sock);
cancelEx(Socket sock);
protected:
constructorInit();
public:
protected:
cancelIntern(string uh);
public:
protected:
startIntern();
public:
protected:
int stopIntern();
public:
protected:
ioThread();
public:
protected:
*bool processCommands();
public:
protected:
doCancelIntern(hash<PollInfo> cinfo);
public:
protected:
sendCmd(string cmd);
public:
};
};
// private symbols
namespace Priv {
// internal poll info
hashdecl PollInfo {
date timeout_date;
Socket sock;
AbstractPollOperation spop;
date to = AsyncSocketIoController::DefaultIoOperationTimeout;
*hash<auto> other;
Queue q();
}
}
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
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