Framework
- Core Foundation
Overview
A CFMachPort object is a wrapper for a native Mach port (mach
). Mach ports are the native communication channel for the macOS kernel.
CFMachPort does not provide a function to send messages, so you primarily use a CFMachPort object if you need to listen to a Mach port that you obtained by other means. You can get a callback when a message arrives on the port or when the port becomes invalid, such as when the native port dies.
To listen for messages you need to create a run loop source with CFMach
and add it to a run loop with CFRun
.
Important
If you want to tear down the connection, you must invalidate the port (using CFMach
) before releasing the runloop source and the Mach port object.
To send data, you must use the Mach APIs with the native Mach port, which is not described here. Alternatively, you can use a CFMessagePort object, which can send arbitrary data.
Mach ports only support communication on the local machine. For network communication, you have to use a CFSocket object.