serverLoop Run the server accept loop on a listening socket until cancellation is signalled via the cancel pipe. All accepted connections are served on child threads, which are cleaned up before this returns.
:: a typeCtrl KGHC 10.0.0.20260917 · lts/ghc-10.0.x · aa25b89 · 2026-10-10
Modulesemaphore-compat-2.0.1Haskell2010
The Unix domain socket server backing the POSIX semaphore implementation.
The server manages a shared token pool and accepts multiple client connections, each served on its own thread.
Protocol (SOCK_STREAM, one byte per command):
"-" Wait (blocking acquire). Decrements semaphore; replies ".". "?" Try-wait. Decrements if positive and replies "."; otherwise replies "!". "+" Release. Increments pool; replies ".". Rejected with "!" if myCount <= 0 (client has not acquired any tokens on this connection).
Unrecognised bytes are rejected with RspFail.
Per-connection token tracking: the server counts tokens held by each connection (myCount). On disconnect (EOF / ResourceVanished) held tokens are returned to the pool, so a crashing client cannot leak tokens.
Connections are tied to a token, so each token (obtained by
waitOnSemaphore) has its own connection.
serverLoop Run the server accept loop on a listening socket until cancellation is signalled via the cancel pipe. All accepted connections are served on child threads, which are cleaned up before this returns.