Qore AsyncSocketIo Module Reference 2.0
Loading...
Searching...
No Matches
AsyncSocketIo::AsyncSocketIoController Class Reference

Class for controlling async socket I/O. More...

#include <AsyncSocketIoController.qc.dox.h>

Inherits LoggerWrapper.

Public Member Methods

bool cancel (Socket sock)
 Cancels any operation in progress for the given Socket.
 
 cancelEx (Socket sock)
 Cancels any operation in progress for the given Socket.
 
 constructor (*LoggerInterface logger)
 Creates the object.
 
 constructor (bool autostop, *LoggerInterface logger)
 For listener sockets.
 
 destructor ()
 Stops the monitoring thread and destroys the object.
 
hash< SocketPollResultInfoexec (hash< SocketPollOperationInfo > info, *bool replace)
 Executes a socket operation asynchronously and waits for the results.
 
bool getAutostop ()
 Get autostop flag.
 
hash< auto > getInfo ()
 Returns information about the object.
 
bool running ()
 Returns True if the I/O thread is running.
 
 setAutostop (bool autostop=True)
 Set autostop flag.
 
 start ()
 Starts monitoring.
 
 stop ()
 Stops monitoring.
 
 stopClear ()
 Stops monitoring and clears all connections.
 
Queue submit (hash< SocketPollOperationInfo > info, *bool replace)
 Submits a socket operation to be performed and returns a Queue where the results will be returned.
 
 waitStop ()
 Waits for the monitoring thread to stop if it's running.
 

Public Attributes

const DefaultIoOperationTimeout = 30s
 Default I/O timeout duration.
 
const PollEventMap = ...
 Polling event map.
 

Private Member Methods

 cancelIntern (string uh)
 Cancels an operation in progress and sends an appropriate message on the result queue.
 
 constructorInit ()
 Common constructor code.
 
Mutex m ()
 Lock for atomic actions.
 

Private Attributes

bool autostop = True
 Stop monitoring thread when the last operation is complete.
 
hash< string, hash< PollInfo > > cache
 Socket cache; unique hash -> poll info.
 
const IO_ADD = "add"
 I/O thread command: add.
 
const IO_CANCEL = "cancel"
 I/O thread command: cancel.
 
const IO_QUIT = "quit"
 I/O thread command: quit.
 
int tid
 I/O thread TID.
 

Private:Internal Member Methods

Queue cmdq ()
 I/O thread command queue.
 
Counter mcnt ()
 I/O thread counter.
 

Private:Internal Attributes

hash< string, Condition > cancel_cond_map
 Cancel operation waiting Condition; socket unique key -> Condition.
 
hash< SocketPollInfo > sem_info
 Semaphore descriptor info.
 
ReadOnlyFile sem_read
 File to read in the I/O thread.
 
File sem_write
 File to signal the I/O thread.
 

Detailed Description

Class for controlling async socket I/O.

Member Function Documentation

◆ cancel()

bool AsyncSocketIo::AsyncSocketIoController::cancel ( Socket  sock)

Cancels any operation in progress for the given Socket.

Parameters
sockthe socket to cancel any operation in progress for
Returns
True if an operation for the socket was canceled, False if not
Note
Stops the I/O thread if the last operation is canceled and the autostop flag is enabled
See also
cancelEx()

◆ cancelEx()

AsyncSocketIo::AsyncSocketIoController::cancelEx ( Socket  sock)

Cancels any operation in progress for the given Socket.

Parameters
sockthe socket to cancel any operation in progress for
Returns
True if an operation for the socket was canceled, False if not
Note
Stops the I/O thread if the last operation is canceled and the autostop flag is enabled
Exceptions
CONTROLLER-CANCEL-ERRORthrown if the Socket has no operation in progress
See also
cancel()

◆ constructor()

AsyncSocketIo::AsyncSocketIoController::constructor ( bool  autostop,
*LoggerInterface  logger 
)

For listener sockets.

Creates the object

◆ exec()

hash< SocketPollResultInfo > AsyncSocketIo::AsyncSocketIoController::exec ( hash< SocketPollOperationInfo info,
*bool  replace 
)

Executes a socket operation asynchronously and waits for the results.

Parameters
infoa hash with the socket operation and supporting info
replaceif True, then any operation currently in place for the given socket will be replaced
Returns
The result of the asynchronous operation
Exceptions
CONTROLLER-ADD-ERRORinvalid or incomplete data in info; a different operation on this socket is already in progress

◆ start()

AsyncSocketIo::AsyncSocketIoController::start ( )

Starts monitoring.

Exceptions
CONTROLLER-START-ERRORif the I/O thread is already running

◆ submit()

Queue AsyncSocketIo::AsyncSocketIoController::submit ( hash< SocketPollOperationInfo info,
*bool  replace 
)

Submits a socket operation to be performed and returns a Queue where the results will be returned.

Parameters
infoa hash with the socket operation and supporting info
replaceif True, then any operation currently in place for the given socket will be replaced
Returns
Queue a Queue that will have the result of the operation pushed to it
Exceptions
CONTROLLER-ADD-ERRORinvalid or incomplete data in info; a different operation on this socket is already in progress