|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | NetQueueConfig |
| struct | NetAddr |
| struct | NetPktInfo |
| Per-datagram information the IP layer carries alongside the payload. More... | |
| struct | NetMessage |
| A received packet, as delivered to a handler. More... | |
| struct | NetMsgQueue |
| Simple intrusive FIFO of NetMessage, linked through NetMessage::next. More... | |
Macros | |
| #define | NET_INVALID_HANDLE ((NetSockHandle)-1) |
An invalid socket handle. Matches both INVALID_SOCKET (Windows) and a negative fd (Unix). | |
| #define | NET_FILTER_RING_SEGSZ 16384 |
| #define | netMsgQueueEmpty(q) ((q)->head == NULL) |
Typedefs | |
| typedef intptr | NetSockHandle |
Platform-neutral OS socket handle: a Windows SOCKET or a Unix file descriptor. | |
| typedef struct NetQueueConfig | NetQueueConfig |
| typedef uint64 | NetTimerId |
| Handle to an armed timer, unique for the lifetime of its queue. | |
| typedef struct NetAddr | NetAddr |
| typedef enum NetEcn | NetEcn |
| Explicit Congestion Notification codepoint, as carried in the IP header. | |
| typedef struct NetPktInfo | NetPktInfo |
| Per-datagram information the IP layer carries alongside the payload. | |
| typedef struct NetMessage | NetMessage |
| A received packet, as delivered to a handler. | |
| typedef struct NetMsgQueue | NetMsgQueue |
| Simple intrusive FIFO of NetMessage, linked through NetMessage::next. | |
Functions | |
| void | netMsgQueuePush (NetMsgQueue *q, NetMessage *msg) |
| NetMessage * | netMsgQueuePop (NetMsgQueue *q) |
Common types and enumerations used in the networking module.
| #define NET_FILTER_RING_SEGSZ 16384 |
Segment size for a stream filter's boundary rings (encOut / decOut) and the flow's encode staging ring. A small default; revisit if a real multi-stage chain profiles badly.
Definition at line 185 of file net_shared.h.
| #define netMsgQueueEmpty | ( | q | ) | ((q)->head == NULL) |
bool netMsgQueueEmpty(NetMsgQueue *q);
Tests whether a message queue has nothing in it
| q | Queue to test |
Definition at line 427 of file net_shared.h.
Network address structure
Byte order differs by field:
port and scope are host byte order, ordinary integers.ipv4 is host order too: ipv4[0] is the least significant octet, so all four bytes can be treated together as a uint32.ipv6 is stored in network order exactly as it travels on the wire, ipv6[0] first – IPv6 addresses are just a 16-byte identifier with no meaningful "host order". Explicit Congestion Notification codepoint, as carried in the IP header.
The values are the two bits themselves, so a codepoint can be written to or read from a packet without translation. A router that is becoming congested rewrites either ECT mark to NET_ECN_CE instead of dropping the packet, which lets a transport that understands it slow down a round trip earlier than loss would have told it to.
| typedef struct NetMessage NetMessage |
A received packet, as delivered to a handler.
Arrives as NetEvent.recv.msg (a complete datagram), NetEvent.refused.msg (a packet from a source with no flow), or through a netsocketRecvMsgs() callback. Read the payload from buf and the peer's address from addr. The message itself is only valid until the handler returns – to keep the payload without copying it, take ownership of the buffer (see buf).
| typedef struct NetMsgQueue NetMsgQueue |
Simple intrusive FIFO of NetMessage, linked through NetMessage::next.
The boundary storage between datagram filter chain stages (see NetDatagramFilter::encOut / decOut in Filters) – the message-queue analog of the byte-oriented BufRing used between NetStreamFilter stages. It needs no locking of its own: every driver pass runs under the owning flow's filter lock, so only one thread is ever inside a chain.
| typedef struct NetPktInfo NetPktInfo |
Per-datagram information the IP layer carries alongside the payload.
On a received datagram this says which of the machine's own addresses the datagram was sent to and how the path marked it. On a send it asks for the same two things: leave from this local address, and put this mark on the packet.
Both fields are optional and both have a have flag, because a platform that cannot report or set one must be distinguishable from one that reported "no mark" – a transport doing ECN has to know which it is before it starts marking packets.
| typedef struct NetQueueConfig NetQueueConfig |
Creation-time configuration for a NetQueue.
Start from a preset and override what you need:
| typedef uint64 NetTimerId |
Handle to an armed timer, unique for the lifetime of its queue.
Returned by netflowAddTimer() and passed back to netflowCancelTimer() / netflowRearmTimer(). Zero is never a valid timer and means "no timer" everywhere it appears.
Definition at line 210 of file net_shared.h.
| enum NetAddrType |
Network address types.
| Enumerator | |
|---|---|
| NA_Unknown | Unknown or invalid. |
| NA_IPv4 | IPv4 address. |
| NA_IPv6 | IPv6 address. |
Definition at line 269 of file net_shared.h.
| enum NetCloseReason |
Why a flow was closed, carried on NET_FlowClosed.
Only NCR_Reclaimed can resurrect: it means the queue guessed the peer was gone, and an arriving packet can prove that guess wrong. Every other reason is final.
| Enumerator | |
|---|---|
| NCR_None | Not closing. |
| NCR_Reclaimed | Reclaimed under flow cap pressure (resurrectable) |
| NCR_AppClosed | Application called netflowClose() |
| NCR_PeerClosed | Stream peer closed the connection cleanly. |
| NCR_Error | Connection reset or other fatal socket error. |
| NCR_SocketClosed | The owning socket was closed with flows still live. |
| NCR_Shutdown | The queue is shutting down. |
Definition at line 166 of file net_shared.h.
| enum NetConnectionState |
Network connection states (for event notification)
| Enumerator | |
|---|---|
| NCS_NotConnected | Not connected. |
| NCS_Connecting | Connection in progress. |
| NCS_Connected | Connected. |
Definition at line 177 of file net_shared.h.
| enum NetConnectPref |
Address-family preference for outbound connect, applied to the resolved address list after DNS lookup. Most applications can leave this at NCP_Default; use the other values when a deployment needs to force or exclude a family (an IPv4-only network, for example).
Definition at line 40 of file net_shared.h.
| enum NetEcn |
Explicit Congestion Notification codepoint, as carried in the IP header.
The values are the two bits themselves, so a codepoint can be written to or read from a packet without translation. A router that is becoming congested rewrites either ECT mark to NET_ECN_CE instead of dropping the packet, which lets a transport that understands it slow down a round trip earlier than loss would have told it to.
Definition at line 312 of file net_shared.h.
| enum NetErrorCode |
Network error codes.
Definition at line 243 of file net_shared.h.
| enum NetFilterNotify |
Filter notification code, carried as the payload of a NET_FilterNotify event (see Filters)
A filter raises one of these through netflowfilterNotify() when it reaches a milestone the application should hear about. Confining filter signals to their own enum – delivered on a dedicated event with a dedicated payload arm – means a filter can raise application-visible notifications without being able to forge an ordinary NET_ event whose payload it could not populate correctly.
Definition at line 195 of file net_shared.h.
| enum NetQueueFlags |
Flags for creating a NetQueue.
Definition at line 23 of file net_shared.h.
| enum NetSocketOpFlags |
Flags for socket send/receive operations.
Definition at line 121 of file net_shared.h.
| enum NetSocketState |
State of a network socket.
Definition at line 153 of file net_shared.h.
| enum NetSocketType |
Socket types.
Definition at line 134 of file net_shared.h.
| enum NetTimerFlags |
Flags controlling how an armed timer behaves.
Definition at line 213 of file net_shared.h.
|
inline |
Remove and return the oldest message in a message queue
Ownership passes to the caller. A filter consuming its input queue pops from src in a loop until this returns NULL, or stops early to leave the rest for a later pass.
| q | Queue to pop from |
Definition at line 453 of file net_shared.h.
|
inline |
Append a message to the end of a message queue
Takes ownership of the message. This is how a datagram filter stage emits output: push onto self->encOut for the wire direction, self->decOut for the application direction.
| q | Queue to append to |
| msg | Message to append (ownership transferred) |
Definition at line 436 of file net_shared.h.
References NetMsgQueue::tail.