Windows completion-port dispatcher object that multiplexes posted callbacks and overlapped completions. The object provides callback posting, blocking or polling dispatch, one wake helper, and one exported opaque completion-port handle.
dispatcher is one exported object that bundles callback schemas, dispatch operations, one cleanup helper, and the completion-port handle used by them.
completionPort: opaque completion-port handle stored as Natx.OnCallback: callback schema that receives one context: Natx.OnEventRef: callback schema that receives context: Natx, numberOfBytesTransferred: Nat32, and error: Nat32.Context: helper schema for one embedded OVERLAPPED, one completion callback, and one user context value.| Entry form | Completion key | lpOverlapped |
Dispatched callback | User payload source |
|---|---|---|---|---|
| Posted callback | Nonzero code pointer to one OnCallback |
One posted Natx payload value |
OnCallback |
The context argument passed to post |
| Overlapped completion | 0nx |
Address of the embedded dispatcher.Context.overlapped field |
dispatcher.Context.onEvent |
The stored dispatcher.Context.context plus transferred bytes and completion error |
dispatch (--): waits indefinitely until one posted callback or completion event becomes available and dispatches exactly one entry.tryDispatch (-- handled): polls once with zero timeout, dispatches exactly one available entry when present, and otherwise returns FALSE.post (context callback --): posts one callback together with one user Natx payload. The callback must not be NIL.wakeOne (--): posts one internal no-op callback with 0nx payload so that one blocked dispatch wait can resume.Context is caller-owned storage for one overlapped completion, and its embedded overlapped field is the object passed to Windows overlapped and completion-port APIs.Context.overlapped is the first field of Context, so the returned OVERLAPPED Ref can be reinterpreted as the start of the surrounding Context object when the queue entry is dispatched.post encodes the callback in the completion key and the user Natx payload in the queued lpOverlapped value.0nx, so nonzero completion keys distinguish posted callbacks from I/O completion entries.Natx payload passed to post.Context.onEvent and receive the stored context together with the transferred-byte count and the completion error value.dispatch waits through GetQueuedCompletionStatusEx with infinite timeout, while tryDispatch uses zero timeout.DIE runs Winsock cleanup and closes the completion-port handle.DIE prints diagnostics when those cleanup calls fail.