Skip to content

Instantly share code, notes, and snippets.

@creachadair
Last active July 27, 2026 03:07
Show Gist options
  • Select an option

  • Save creachadair/cfa97f09955be3ecfe62f2d5a24102c8 to your computer and use it in GitHub Desktop.

Select an option

Save creachadair/cfa97f09955be3ecfe62f2d5a24102c8 to your computer and use it in GitHub Desktop.
Socket API

BSD (POSIX) Socket API Flow

Edges in this graph indicate order dependencies. Broadly, you may only legally use an operation if you have performed all the operations on some path to it, starting from "ø", the entry point. Error paths are not illustrated. Once created, a socket can be close'd at any time.

"Legally" here is intentionally somewhat imprecise. For example, most implementations will not report an error if you call recvmsg on a socket that has no address bound to it; however, no message will ever become available, and if non-blocking, the call will time out.

graph TD
  O(("ø")) --> S
  S --> GSO[getsockopt]
  S --> SSO[setsockopt]
  S[socket] --> B[bind]
  S --> CL[close]
  S --> TXM{{sendmsg}}
  C --> TX{{send}}
  C --> RX{{recv}}
  C --> SD[shutdown]
  S --> C[connect]
  B --> L
  S --> L[listen]
  B --> RXM{{recvmsg}}
  L --> A[accept]
  A --> SD[shutdown]
  A --> TX
  A --> RX
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment