Base class for all async requests, holding state and type. More...
#include <Async.h>
Public Types | |
enum class | Type : uint8_t { LoopTimeout , LoopWakeUp , LoopWork , ProcessExit , SocketAccept , SocketConnect , SocketSend , SocketReceive , SocketClose , FileRead , FileWrite , FileClose , FilePoll } |
Type of async request. More... | |
Public Member Functions | |
void | setDebugName (const char *newDebugName) |
AsyncEventLoop * | getEventLoop () const |
Get the event loop associated with this AsyncRequest. More... | |
void | cacheInternalEventLoop (AsyncEventLoop &loop) |
Caches the event loop associated with this AsyncRequest. More... | |
Result | setThreadPoolAndTask (ThreadPool &pool, AsyncTask &task) |
Sets the thread pool and task to use for this request. More... | |
void | resetThreadPoolAndTask () |
Resets anything previously set with setThreadPoolAndTask. More... | |
AsyncRequest (Type type) | |
Constructs a free async request of given type. More... | |
Result | stop () |
Stops the async operation. More... | |
bool | isFree () const |
Public Attributes | |
AsyncRequest * | next = nullptr |
AsyncRequest * | prev = nullptr |
Protected Member Functions | |
Result | validateAsync () |
void | queueSubmission (AsyncEventLoop &eventLoop) |
Protected Attributes | |
AsyncEventLoop * | eventLoop = nullptr |
AsyncTask * | asyncTask = nullptr |
Friends | |
struct | AsyncEventLoop |
Base class for all async requests, holding state and type.
An async operation is struct derived from AsyncRequest asking for some I/O to be done made to the OS.
Every async operation has an associated callback that is invoked when the request is fulfilled. If the start
function returns a valid (non error) Return code, then the user callback will be called both in case of success and in case of any error.
If the function returns an invalid Return code or if the operation is manually cancelled with SC::AsyncRequest::stop, then the user callback will not be called.
result.reactivateRequest(true)
is NOT called) then the async request can be freed as soon as the user callback is called (even inside the callback itself).result.reactivateRequest(true)
is called) then the async cannot be freed as it's still in use.Some implementation details: SC::AsyncRequest::state dictates the lifetime of the async request according to a state machine.
Regular Lifetime of an Async request (called just async in the paragraph below):
Cancellation of an async: An async can be cancelled at any time:
Any other case is considered an error (trying to cancel an async already being cancelled or being teardown).
|
strong |
Type of async request.
Enumerator | |
---|---|
LoopTimeout | Request is an AsyncLoopTimeout object. |
LoopWakeUp | Request is an AsyncLoopWakeUp object. |
LoopWork | Request is an AsyncLoopWork object. |
ProcessExit | Request is an AsyncProcessExit object. |
SocketAccept | Request is an AsyncSocketAccept object. |
SocketConnect | Request is an AsyncSocketConnect object. |
SocketSend | Request is an AsyncSocketSend object. |
SocketReceive | Request is an AsyncSocketReceive object. |
SocketClose | Request is an AsyncSocketClose object. |
FileRead | Request is an AsyncFileRead object. |
FileWrite | Request is an AsyncFileWrite object. |
FileClose | Request is an AsyncFileClose object. |
FilePoll | Request is an AsyncFilePoll object. |
|
inline |
Constructs a free async request of given type.
type | Type of this specific request |
|
inline |
Caches the event loop associated with this AsyncRequest.
Used to cache eventLoop pointer before starting the AsyncRequest.
|
inline |
Get the event loop associated with this AsyncRequest.
void SC::AsyncRequest::resetThreadPoolAndTask | ( | ) |
Resets anything previously set with setThreadPoolAndTask.
Result SC::AsyncRequest::setThreadPoolAndTask | ( | ThreadPool & | pool, |
AsyncTask & | task | ||
) |
Sets the thread pool and task to use for this request.
Result SC::AsyncRequest::stop | ( | ) |
Stops the async operation.
Ask to stop current async operation
true
if the stop request has been successfully queued