6#include "dawn/io/stream_notifier.hxx"
10#include "dawn/common/poll_loop.hxx"
11#include "dawn/io/common.hxx"
15CStreamNotifier::CStreamNotifier()
23CStreamNotifier::~CStreamNotifier()
41void CStreamNotifier::thread()
64 callbacks.
onPollReady = [](
void *priv,
struct pollfd *pollfds, nfds_t nfds,
int pollRet) ->
int
77 self =
static_cast<decltype(ctx) *
>(priv)->self;
85 self->io->
getData(*self->data, self->batch);
89 for (SIONotifier &user : self->users)
93 user.cb(user.priv, self->data);
103int CStreamNotifier::start()
107 DAWNERR(
"No IO bound to stream notifier\n");
117int CStreamNotifier::stop()
128 DAWNERR(
"IO pointer is null\n");
134 DAWNERR(
"isNotify=false!\n");
140 if (io !=
nullptr && io != n.
io)
142 DAWNERR(
"Stream notifier already bound to different IO\n");
150 if (threadCtl.hasThreadObject())
152 DAWNERR(
"Cannot bind new IO after thread started\n");
157 batch = n.
io->getNotifyBatch();
161 DAWNERR(
"Failed to allocate data for stream notifier\n");
int getData(IODataCmn &data, size_t len, size_t offset=0)
Get data from I/O (public interface with stats tracking).
virtual bool isNotify() const =0
Check if IO supports notifications.
virtual int getFd() const
Get file descriptor for notifications.
io_ddata_t * ddata_alloc(size_t batch, size_t chunk_size=0)
Allocate data buffer for this I/O.
static int run(CThreadedObject &threadCtl, struct pollfd *pfds, nfds_t nfds, int timeoutMs, const SPollLoopCallbacks &callbacks, void *priv)
Run poll loop until quit is requested.
Stream-based I/O notifier with dedicated thread per I/O.
int regNotifier(SIONotifier n)
Register I/O notification callback.
int threadStop()
Stop the worker thread.
int threadStart()
Start the worker thread.
void setThreadFunc(Func &&func)
Assign the function executed by threadStart().
Out-of-tree user-extension hooks for Dawn.
Notifier registration structure.
CIOCommon * io
I/O object pointer.
Callback set for poll-based worker loops.
void(* afterPoll)(void *priv, struct pollfd *pfds, nfds_t nfds, int ret)
Optional hook called after each poll() return.
int(* onPollReady)(void *priv, struct pollfd *pfds, nfds_t nfds, int pollRet)
Optional hook called when poll() reports ready descriptors.
int(* beforePoll)(void *priv, struct pollfd *pfds, nfds_t nfds)
Optional hook called before each poll() call.