|
CX Framework
Cross-platform C utility framework
|
NetQueue manages one or more sockets and a thread pool of workers. More...
#include <queue.h>
Public Member Functions | |
| Weak (ObjInst) *handlerWeak | |
| Context passed to queue-wide handlers, set by setHandlersObj() – NULL when handlerCtx is in use instead. | |
| atomic (uint32) gcLastLo | |
| Timestamp of the last opportunistic GC pass, used to rate-limit it. | |
| atomic (uint32) droppedNoBuf | |
| Datagrams dropped for lack of a receive buffer. | |
| atomic (uint32) nflows | |
| atomic (uint32) timersLive | |
Number of armed timers, readable without taking timerLock | |
| atomic (uint32) shutdownReq | |
| Set when shutdown begins, so ingest stops producing and addSocket is refused. | |
Data Fields | |
| NetQueueConfig | conf |
| NetHandlers | handlers |
| Queue-wide fallback handlers. | |
| void * | handlerCtx |
| RWLock | handlerLock |
| Guards handlers/handlerCtx/handlerWeak against a concurrent setHandlers()/setHandlersObj() | |
| hashtable | sockets |
| Sockets this queue is managing, keyed by pointer identity. | |
| RWLock | lock |
| PrQueue | runq |
| Flows with work pending, waiting for a worker to claim them. | |
| NetPool * | pool |
| Shared, capped storage every NetMessage on this queue is drawn from. | |
| NetTimerEntry * | timers |
| Armed timers across every flow on this queue, kept as a min-heap ordered by deadline. | |
| uint32 | ntimers |
Entries in use in timers | |
| uint32 | timersCap |
Entries allocated in timers | |
| uint64 | timerSerial |
| Source of NetTimerId values; never reused, never 0. | |
| hashtable | timerIdx |
Maps a timer id to its current index in timers | |
| Mutex | timerLock |
| Guards the timer heap and every flow's list of armed timer ids. | |
| sa_Thread | workers |
| Dispatch worker threads draining the runqueue (empty in polled mode) | |
| Semaphore | runqSema |
| Posted once per flow enqueued; dispatch workers wait on it when the runqueue is dry. | |
| NetSendPumpFn | sendPump |
| Backend hook invoked when the send path leaves outbound data queued on a socket. | |
| void * | sendCtx |
| NetWakeFn | wake |
| Backend hook that wakes a parked wait so it can recompute its timeout. | |
| void * | wakeCtx |
| Context passed to wake, normally the derived queue. | |
NetQueue manages one or more sockets and a thread pool of workers.
| NetQueue::atomic | ( | uint32 | ) |
Datagrams dropped for lack of a receive buffer.
A silent drop looks just like a flaky network. A nonzero counter turns "the network seems unreliable" into "the buffer pool is too small or a callback is too slow" right away.
| NetQueue::atomic | ( | uint32 | ) |
Timestamp of the last opportunistic GC pass, used to rate-limit it.
The runqueue and receive pool grow under load and only give that memory back when prqCollect() runs; netqueue_maint() runs it periodically from whichever thread just drained the runqueue and is about to go idle.
| NetQueue::atomic | ( | uint32 | ) |
Flows currently live across every socket on this queue
| NetQueueConfig NetQueue::conf |
| void* NetQueue::handlerCtx |
| NetHandlers NetQueue::handlers |
Queue-wide fallback handlers.
The last level of the per-field fallthrough described in Event Handlers, and generally the right place for logging and error handling while sockets and flows override the events they actually care about.
| NetPool* NetQueue::pool |
Shared, capped storage every NetMessage on this queue is drawn from.
A separate object rather than a member so that flows and filter stages – which can be torn down holding messages at a point where the queue is no longer reachable from them – can keep their own reference and always have somewhere to return a buffer. See Buffer Pool.
| PrQueue NetQueue::runq |
Flows with work pending, waiting for a worker to claim them.
One instance per queue, safe for many ingest threads to push to and many workers to pop from at once. Holds its own strong reference to a queued flow, so closing a socket can't free a flow out from under a worker that's mid-batch on it.
| void* NetQueue::sendCtx |
| NetSendPumpFn NetQueue::sendPump |
Backend hook invoked when the send path leaves outbound data queued on a socket.
netsocketSend() calls this after its own flush when data couldn't all go out at once, so the backend can arrange for the rest to drain – a readiness backend (select) wakes its ingest thread to add write interest, a completion backend (IOCP) posts an overlapped send. NULL in polled mode, where tick() rebuilds the watch set every call. See NetSendPumpFn.
| Mutex NetQueue::timerLock |
| NetTimerEntry* NetQueue::timers |
| NetWakeFn NetQueue::wake |
| sa_Thread NetQueue::workers |
Dispatch worker threads draining the runqueue (empty in polled mode)
Each worker blocks on runqSema and drains the runqueue through netqueue_dispatch(). A backend that merges ingest and dispatch into one wait call (IOCP) manages its own threads instead and leaves this empty. A nonzero count means threaded mode.