CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
NetQueue Struct Reference

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.
 
NetPoolpool
 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.
 

Detailed Description

NetQueue manages one or more sockets and a thread pool of workers.

Definition at line 79 of file queue.h.

Member Function Documentation

◆ atomic() [1/3]

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.

◆ atomic() [2/3]

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.

◆ atomic() [3/3]

NetQueue::atomic ( uint32  )

Flows currently live across every socket on this queue

Field Documentation

◆ conf

NetQueueConfig NetQueue::conf

Configuration settings for this queue

Definition at line 89 of file queue.h.

◆ handlerCtx

void* NetQueue::handlerCtx

Context passed to queue-wide handlers, set by setHandlers()

Definition at line 96 of file queue.h.

◆ handlers

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.

Definition at line 95 of file queue.h.

◆ lock

RWLock NetQueue::lock

Protects the socket hash

Definition at line 102 of file queue.h.

◆ pool

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.

Definition at line 114 of file queue.h.

◆ runq

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.

Definition at line 108 of file queue.h.

◆ sendCtx

void* NetQueue::sendCtx

Context passed to sendPump, normally the derived queue

Definition at line 155 of file queue.h.

◆ sendPump

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.

Definition at line 154 of file queue.h.

◆ timerLock

Mutex NetQueue::timerLock

Guards the timer heap and every flow's list of armed timer ids.

Lock order is connectLock -> timerLock, never the reverse. Never held during a callback.

Definition at line 138 of file queue.h.

◆ timers

NetTimerEntry* NetQueue::timers

Armed timers across every flow on this queue, kept as a min-heap ordered by deadline.

Every entry holds a strong reference to its flow.

Definition at line 130 of file queue.h.

◆ wake

NetWakeFn NetQueue::wake

Backend hook that wakes a parked wait so it can recompute its timeout.

Called when a timer is armed with a deadline nearer than the one the backend is currently waiting on. Set even in polled mode. NULL if the backend has no wait to interrupt.

Definition at line 160 of file queue.h.

◆ workers

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.

Definition at line 145 of file queue.h.


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