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

Configuring a CFMessagePort Object

func CFMessagePortSetInvalidationCallBack(CFMessagePort!, CFMessagePortInvalidationCallBack!)

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

func CFMessagePortSetName(CFMessagePort!, CFString!) -> Bool

Sets the name of a local CFMessagePort object.

Using a Message Port

func CFMessagePortInvalidate(CFMessagePort!)

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

func CFMessagePortSetDispatchQueue(CFMessagePort!, DispatchQueue!)

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

Examining a Message Port

func CFMessagePortGetInvalidationCallBack(CFMessagePort!) -> CFMessagePortInvalidationCallBack!

Returns the invalidation callback function for a CFMessagePort object.

func CFMessagePortGetName(CFMessagePort!) -> CFString!

Returns the name with which a CFMessagePort object is registered.

func CFMessagePortIsRemote(CFMessagePort!) -> Bool

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

func CFMessagePortIsValid(CFMessagePort!) -> Bool

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

Getting the CFMessagePort Type ID

func CFMessagePortGetTypeID() -> CFTypeID

Returns the type identifier for the CFMessagePort opaque type.

Callbacks

typealias CFMessagePortCallBack

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

typealias CFMessagePortInvalidationCallBack

Callback invoked when a CFMessagePort object is invalidated.

Data Types

struct CFMessagePortContext

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

class CFMessagePort

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.