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()
43 SPollLoopCallbacks callbacks;
48 CStreamNotifier *self;
64 callbacks.
onPollReady = [](
void *priv,
struct pollfd *pollfds, nfds_t nfds,
int pollRet) ->
int
66 CStreamNotifier *self;
77 self =
static_cast<decltype(ctx) *
>(priv)->self;
86 if (self->io->
getData(*self->data, self->batch) < 0)
97 user.cb(user.priv, self->data);
107int CStreamNotifier::start()
111 DAWNERR(
"No IO bound to stream notifier\n");
117 threadCtl.setThreadFunc([
this]() { thread(); });
118 return threadCtl.threadStart();
121int CStreamNotifier::stop()
125 return threadCtl.threadStop();
132 DAWNERR(
"IO pointer is null\n");
138 DAWNERR(
"isNotify=false!\n");
144 if (io !=
nullptr && io != n.
io)
146 DAWNERR(
"Stream notifier already bound to different IO\n");
154 if (threadCtl.hasThreadObject())
156 DAWNERR(
"Cannot bind new IO after thread started\n");
161 batch = n.
io->getNotifyBatch();
165 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.
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.
int regNotifier(SIONotifier n)
Register I/O notification callback.
Out-of-tree user-extension hooks for Dawn.
Notifier registration structure.
CIOCommon * io
I/O object pointer.
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.