| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
System.Semaphore.Internal.Posix.Server
Description
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.
Documentation
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.
pattern CmdTryWait :: Word8 Source #
pattern CmdRelease :: Word8 Source #