|
CX Framework
Cross-platform C utility framework
|
#include <socket.h>
Public Member Functions | |
| Weak (NetQueue) *queue | |
| NetQueue this socket is registered to (may be NULL) | |
| atomic (uint32) state | |
| See NetSocketState enum. | |
| atomic (bool) canSend | |
| Send buffer empty; can send immediately. | |
| Weak (ObjInst) *handlerWeak | |
| Context passed to per-socket handlers, set by setHandlersObj() – NULL when handlerCtx is in use instead. | |
| atomic (uint32) connectGen | |
| Attempt generation, bumped once per connect attempt. | |
Data Fields | |
| NetSocketType | type |
| NetSockHandle | handle |
| Platform-neutral OS handle, set by the platform factory. | |
| NetAddr | local |
| Local end, filled in by bind() | |
| NetAddr | remote |
| Remote address (for connected sockets only) | |
| uint32 | mru |
| bool | recvInfo |
| The OS is reporting per-datagram IP information; see setRecvInfo() | |
| NetSocketBufs | bufs |
Type-specific send/receive buffers; which arm is live depends on type | |
| Mutex | recvLock |
| Exclusive access to the socket's receive buffer. | |
| Mutex | sendLock |
| size_t | sendHigh |
| Send fails over this many bytes queued. | |
| size_t | sendLow |
| NET_SendReady fires when the queue drains below this. | |
| size_t | sendQueued |
| Bytes waiting in the datagram send queue, guarded by sendLock. | |
| bool | sendBlocked |
| A send returned false at the high watermark and is waiting for NET_SendReady. | |
| bool | sendPending |
| A completion backend has an overlapped send in flight for this socket. | |
| NetHandlers * | handlers |
| Per-socket handler overrides, optional. | |
| void * | handlerCtx |
| RWLock | handlerLock |
| Guards handlers/handlerCtx/handlerWeak against a concurrent setHandlers()/setHandlersObj() | |
| hashtable | flows |
| Flows keyed by peer address (datagram) or stream id (QUIC). Not used by stream sockets. | |
| RWLock | flowLock |
| NetFlow * | flow |
| Stream: the single flow for this connection. QUIC: the connection control flow. Not used by datagram sockets. | |
| sa_NetFilter | filters |
| Filters attached to this socket, ordered application -> wire, or empty for none. | |
| NetConnectPref | connectPref |
| Per-socket address-family preference override; NCP_Default inherits the queue's setting when the socket is added (see NetQueue::connectPref) | |
| sa_NetAddr | connQueue |
| List of fallback addresses to try to connect to if pending connect fails. | |
| int32 | connectIdx |
| NetTimerId | connectTimer |
| Timer arming the in-flight connect attempt's deadline, or 0 when none is armed. | |
| Mutex | connectLock |
| Serializes the connect-advance transition; see connectTimer. | |
Network Socket This is a base class; the actual socket implemention will be a derived class provided by the OS abstraction layer.
| NetSocket::atomic | ( | uint32 | ) |
Attempt generation, bumped once per connect attempt.
Lets a completion whose attempt already timed out and was superseded recognize that and just clean itself up instead of acting on a stale result.
| NetSocketBufs NetSocket::bufs |
Type-specific send/receive buffers; which arm is live depends on type
A stream socket has a receive ring and a send chain; a datagram socket has neither and just a send queue (its packets are pooled buffers on flow inboxes instead). See NetSocketBufs – constructed and torn down by hand in NetSocket_init() / _destroy(), since generated code cannot see into a union.
| int32 NetSocket::connectIdx |
| Mutex NetSocket::connectLock |
| NetTimerId NetSocket::connectTimer |
Timer arming the in-flight connect attempt's deadline, or 0 when none is armed.
Three things can complete one connect attempt – the backend, netsocketClose(), and the attempt timing out – and cancelling this timer is what arbitrates between them. A cancel succeeds only if the timer had not already been popped for delivery, so exactly one of the three wins and the losers see either a zeroed field or a failed cancel. Set when an attempt begins, cleared when it resolves.
| sa_NetAddr NetSocket::connQueue |
List of fallback addresses to try to connect to if pending connect fails.
Filled in by the resolver, then reordered by family per connectPref. The connect state machine tries each address in turn, falling through to the next entry whenever an attempt fails or times out.
| sa_NetFilter NetSocket::filters |
Filters attached to this socket, ordered application -> wire, or empty for none.
These are factories, not data-plane stages: each one creates a NetFlowFilter for every flow the socket owns, and the transform itself happens on the flow. See Filters.
| NetFlow* NetSocket::flow |
Stream: the single flow for this connection. QUIC: the connection control flow. Not used by datagram sockets.
Created automatically during socket init, so stream consumers never construct a flow themselves. A QUIC socket has this and a flow table: connection-level work – packet decryption, ACK generation, loss recovery, the handshake – is ordered on this one flow, while each of its streams gets a flow of its own that can run on another worker.
| RWLock NetSocket::flowLock |
| hashtable NetSocket::flows |
Flows keyed by peer address (datagram) or stream id (QUIC). Not used by stream sockets.
Holds strong references – the socket owns its flows, and the flow's back-pointer to the socket is weak to avoid a reference cycle. Which key a socket's table uses is fixed by type, so NetFlow::key is only meaningful on a QUIC socket's flows.
| NetSockHandle NetSocket::handle |
| void* NetSocket::handlerCtx |
| NetHandlers* NetSocket::handlers |
Per-socket handler overrides, optional.
Resolved per field between the flow's set and the queue-wide set; see Event Handlers.
| NetAddr NetSocket::local |
| bool NetSocket::recvInfo |
The OS is reporting per-datagram IP information; see setRecvInfo()
Datagram sockets only. While set, the ingest path asks the OS for the local address and ECN mark of every datagram and delivers them on NetMessage::info.
| bool NetSocket::sendBlocked |
A send returned false at the high watermark and is waiting for NET_SendReady.
Set when netsocketSend() refuses because the backlog is over sendHigh, cleared once the queue drains back below sendLow and the event fires. Guarded by sendLock.
| size_t NetSocket::sendHigh |
Send fails over this many bytes queued.
On a QUIC socket this is per stream rather than per socket: how much one stream will hold for the application before netflowSend() starts refusing.
| Mutex NetSocket::sendLock |
| size_t NetSocket::sendLow |
NET_SendReady fires when the queue drains below this.
On a QUIC socket this reads the other way round, since a stream's backlog is bounded by what the peer allows rather than by the queue: NET_SendReady fires once the stream has this many bytes of room. A refused send always sets the bar at least as high as what it asked for, so this only matters when it asked for less.
| bool NetSocket::sendPending |
A completion backend has an overlapped send in flight for this socket.
Set by the IOCP backend while a WSASend/WSASendTo it posted is outstanding, cleared when that completion arrives. While set, the normal synchronous flush is suppressed so it can't touch bytes the in-flight send already owns – doing so could send the same bytes twice and corrupt the connection. Always false on readiness backends. Guarded by sendLock.
| size_t NetSocket::sendQueued |
| NetSocketType NetSocket::type |