CFMessagePort

Overview

CFMessagePort objects provide a communications channel that can transmit arbitrary data between multiple threads or processes on the local machine.

You create a local message port with CFMessagePortCreateLocal and make it available to other processes by giving it a name, either when you create it or later with CFMessagePortSetName. Other processes then connect to it using CFMessagePortCreateRemote, specifying the name of the port.

To listen for messages, you need to create a run loop source with CFMessagePortCreateRunLoopSource and add it to a run loop with CFRunLoopAddSource.

Your message port’s callback function will be called when a message arrives. To send data, you store the data in a CFData object and call CFMessagePortSendRequest. You can optionally have the function wait for a reply and return the reply in another CFData object.

Message ports only support communication on the local machine. For network communication, you have to use a CFSocket object.

Topics

Creating a CFMessagePort Object

CFMessagePortCreateLocal

Returns a local CFMessagePort object.

CFMessagePortCreateRemote

Returns a CFMessagePort object connected to a remote port.

Configuring a CFMessagePort Object

CFMessagePortCreateRunLoopSource

Creates a CFRunLoopSource object for a CFMessagePort object.

CFMessagePortSetInvalidationCallBack

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

CFMessagePortSetName

Sets the name of a local CFMessagePort object.

Using a Message Port

CFMessagePortInvalidate

Invalidates a CFMessagePort object, stopping it from receiving or sending any more messages.

CFMessagePortSendRequest

Sends a message to a remote CFMessagePort object.

CFMessagePortSetDispatchQueue

Schedules callbacks for the specified message port on the specified dispatch queue.

Examining a Message Port

CFMessagePortGetContext

Returns the context information for a CFMessagePort object.

CFMessagePortGetInvalidationCallBack

Returns the invalidation callback function for a CFMessagePort object.

CFMessagePortGetName

Returns the name with which a CFMessagePort object is registered.

CFMessagePortIsRemote

Returns a Boolean value that indicates whether a CFMessagePort object represents a remote port.

CFMessagePortIsValid

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

Getting the CFMessagePort Type ID

CFMessagePortGetTypeID

Returns the type identifier for the CFMessagePort opaque type.

Callbacks

CFMessagePortCallBack

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

CFMessagePortInvalidationCallBack

Callback invoked when a CFMessagePort object is invalidated.

Data Types

CFMessagePortContext

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

CFMessagePortRef

A reference to a message port object.

Constants

CFMessagePortSendRequest Error Codes

Error codes for CFMessagePortSendRequest.

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.