CFMachPort

Overview

A CFMachPort object is a wrapper for a native Mach port (mach_port_t). 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 CFMachPortCreateRunLoopSource and add it to a run loop with CFRunLoopAddSource.

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.

Topics

Creating a CFMachPort Object

CFMachPortCreate

Creates a CFMachPort object with a new Mach port.

CFMachPortCreateWithPort

Creates a CFMachPort object for a pre-existing native Mach port.

Configuring a CFMachPort Object

CFMachPortInvalidate

Invalidates a CFMachPort object, stopping it from receiving any more messages.

CFMachPortCreateRunLoopSource

Creates a CFRunLoopSource object for a CFMachPort object.

CFMachPortSetInvalidationCallBack

Sets the callback function invoked when a CFMachPort object is invalidated.

Examining a CFMachPort Object

CFMachPortGetContext

Returns the context information for a CFMachPort object.

CFMachPortGetInvalidationCallBack

Returns the invalidation callback function for a CFMachPort object.

CFMachPortGetPort

Returns the native Mach port represented by a CFMachPort object.

CFMachPortIsValid

Returns a Boolean value that indicates whether a CFMachPort object is valid and able to receive messages.

Getting the CFMachPort Type ID

CFMachPortGetTypeID

Returns the type identifier for the CFMachPort opaque type.

Callbacks

CFMachPortCallBack

Callback invoked to process a message received on a CFMachPort object.

CFMachPortInvalidationCallBack

Callback invoked when a CFMachPort object is invalidated.

Data Types

CFMachPortContext

A structure that contains program-defined data and callbacks with which you can configure a CFMachPort object’s behavior.

CFMachPortRef

A reference to a CFMachPort object.

See Also

Opaque Types

CFFileDescriptor

The CFFileDescriptor provides an opaque type to monitor file descriptors for read and write activity via CFRunLoop.

CFStringTokenizer

CFStringTokenizer allows you to tokenize strings into words, sentences or paragraphs in a language-neutral way. It supports languages such as Japanese and Chinese that do not delimit words by spaces, as well as de-compounding German compounds. You can obtain Latin transcription for tokens. It also provides language identification API.