Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
SC::AsyncSignal Struct Reference

Starts monitoring a signal, notifying about its reception. More...

#include <Async.h>

Inheritance diagram for SC::AsyncSignal:
SC::AsyncRequest

Classes

struct  CompletionData
 
struct  Result
 

Public Member Functions

SC::Result start (AsyncEventLoop &eventLoop, int num, AsyncSignalOptions options={})
 Sets async request members and calls AsyncEventLoop::start.
 
Result start (AsyncEventLoop &eventLoop)
 Shortcut for AsyncEventLoop::start.
 
- Public Member Functions inherited from SC::AsyncRequest
void setDebugName (const char *newDebugName)
 
void executeOn (AsyncSequence &sequence)
 Adds the request to be executed on a specific AsyncSequence.
 
Result executeOn (AsyncTaskSequence &task, ThreadPool &pool, AsyncThreadPoolMode mode=AsyncThreadPoolMode::NativePreferred)
 Adds the request to be executed on a specific AsyncTaskSequence.
 
void disableThreadPool ()
 Disables the thread-pool usage for this request.
 
 AsyncRequest (Type type)
 Constructs a free async request of given type.
 
Result stop (AsyncEventLoop &eventLoop, Function< void(AsyncResult &)> *afterStopped=nullptr)
 Ask to stop current async operation.
 
bool isFree () const
 Returns true if this request is free.
 
bool isCancelling () const
 Returns true if this request is being cancelled.
 
bool isActive () const
 Returns true if this request is active or being reactivated.
 
Type getType () const
 Returns request type.
 
Result start (AsyncEventLoop &eventLoop)
 Shortcut for AsyncEventLoop::start.
 
void setUserFlags (uint16_t externalFlags)
 Sets user flags, holding some meaningful data for the caller.
 
uint16_t getUserFlags () const
 Gets user flags, holding some meaningful data for the caller.
 
Function< void(AsyncResult &)> * getCloseCallback ()
 Returns currently set close callback (if any) passed to AsyncRequest::stop.
 
const Function< void(AsyncResult &)> * getCloseCallback () const
 

Public Attributes

Function< void(Result &)> callback
 Called when the signal is raised.
 
- Public Attributes inherited from SC::AsyncRequest
AsyncRequestnext = nullptr
 
AsyncRequestprev = nullptr
 

Friends

struct AsyncEventLoop
 

Additional Inherited Members

- Public Types inherited from SC::AsyncRequest
enum class  Type : uint8_t {
  LoopTimeout ,
  LoopWakeUp ,
  LoopWork ,
  ProcessExit ,
  Signal ,
  SocketAccept ,
  SocketConnect ,
  SocketSend ,
  SocketSendTo ,
  SocketReceive ,
  SocketReceiveFrom ,
  FileRead ,
  FileWrite ,
  FileSend ,
  FileReadiness ,
  ExternalCompletion ,
  FileSystemOperation
}
 Type of async request. More...
 
- Protected Member Functions inherited from SC::AsyncRequest
Result checkState ()
 
void queueSubmission (AsyncEventLoop &eventLoop)
 
AsyncTaskSequencegetTask ()
 
bool isThreadPoolForced () const
 
- Protected Attributes inherited from SC::AsyncRequest
AsyncSequencesequence = nullptr
 

Detailed Description

Starts monitoring a signal, notifying about its reception.

AsyncSignal follows the base AsyncRequest lifecycle: after a delivered signal, the request is completed unless the callback calls Result::reactivateRequest(true). AsyncSignalOptions::mode and coalesce are kept as explicit policy fields for future backend-parity work, but portable code should not rely on them for automatic reactivation.

On POSIX systems, signals like SIGINT, SIGTERM, SIGHUP are supported. On Windows, console control signals CTRL_C_EVENT, CTRL_BREAK_EVENT, and CTRL_CLOSE_EVENT are mapped to SIGINT (2), signal 21, and SIGTERM (15) respectively.

Signal watcher capabilities:

  • one watcher for a given signal is supported on all backends.
  • multiple different signals on the same loop are supported on all backends.
  • multiple watchers for the same signal on Windows are supported through the process-wide console signal registry.
  • multiple POSIX watchers for the same signal are backend-dependent and should not be used as a portable fanout mechanism. Prefer one AsyncSignal per process signal and fan out from that callback when portable behavior matters.
// Assuming an already created (and running) AsyncEventLoop named eventLoop
// ...
AsyncSignal asyncSignal;
asyncSignal.callback = [&](AsyncSignal::Result& res)
{
console.print("Signal {} received {} times", res.completionData.signalNumber, res.completionData.deliveryCount);
};
// On Windows, SIGINT (2) -> CTRL_C_EVENT, 21 -> CTRL_BREAK_EVENT, SIGTERM (15) -> CTRL_CLOSE_EVENT
SC_TRY(asyncSignal.start(eventLoop, SIGINT));

Member Function Documentation

◆ start() [1/2]

Result SC::AsyncRequest::start ( AsyncEventLoop & eventLoop)

Shortcut for AsyncEventLoop::start.

◆ start() [2/2]

SC::Result SC::AsyncSignal::start ( AsyncEventLoop & eventLoop,
int num,
AsyncSignalOptions options = {} )

Sets async request members and calls AsyncEventLoop::start.

Member Data Documentation

◆ callback

Function<void(Result&)> SC::AsyncSignal::callback

Called when the signal is raised.


The documentation for this struct was generated from the following file: