Function

CFNetServiceRegisterWithOptions

Makes a CFNetService available on the network.

Declaration

Boolean CFNetServiceRegisterWithOptions(CFNetServiceRef theService, CFOptionFlags options, CFStreamError *error);

Parameters

theService

Network service to register; cannot be NULL. The registration will fail if the service doesn’t have a domain, a type, a name, and an IP address.

options

Bit flags for specifying registration options. Currently, the only registration option is kCFNetServiceFlagNoAutoRename. For details, see CFNetService Registration Options.

error

Pointer to a CFStreamError structure that will be set to an error code and the error code’s domain if an error occurs; or NULL if you don’t want to receive the error code and its domain.

Return Value

TRUE if an asynchronous service registration was started; FALSE if an asynchronous or synchronous registration failed or if a synchronous registration was canceled.

Discussion

If the service is to run in asynchronous mode, you must call CFNetServiceSetClient to associate a callback function with this CFNetService before calling this function.

When registering a service that runs in asynchronous mode, this function returns TRUE if the service contains all of the required attributes and the registration process can start. If the registration process completes successfully, the service is available on the network until you shut down the service by calling CFNetServiceUnscheduleFromRunLoop, CFNetServiceSetClient, and CFNetServiceCancel. If the service does not contain all of the required attributes or if the registration process does not complete successfully, this function returns FALSE.

When registering a service that runs in synchronous mode, this function blocks until an error occurs, in which case this function returns FALSE. Until this function returns FALSE, the service is available on the network. To force this function to return FALSE, thereby shutting down the service, call CFNetServiceCancel from another thread.

The options parameter is a bit flag for specifying service registration options. Currently, kCFNetServiceFlagNoAutoRename is the only supported registration option. If this bit is set and a service of the same name is running, the registration will fail. If this bit is not set and a service of the same name is running, the service that is being registered will be renamed automatically by appending (n) to the service name, where n is a number that is incremented until the service can be registered with a unique name.

Special Considerations

This function is thread safe.

See Also

Network Services

CFNetServiceRef

An opaque reference representing a CFNetService.

CFNetServiceBrowserRef

An opaque reference representing a CFNetServiceBrowser.

CFNetServiceMonitorRef

An opaque reference for a service monitor.

CFNetServiceMonitorType

Record type specifier used to tell a service monitor the type of record changes to watch for.

CFNetServiceClientContext

A structure provided when a CFNetService is associated with a callback function or when a CFNetServiceBrowser is created.

CFNetServicesError

Error codes that may be returned by CFNetServices functions or passed to CFNetServices callback functions.

CFNetServiceBrowserInvalidate

Invalidates an instance of a Network Service browser object.

CFNetServiceBrowserScheduleWithRunLoop

Schedules a CFNetServiceBrowser on a run loop.

CFNetServiceBrowserCreate

Creates an instance of a Network Service browser object.

CFNetServiceBrowserGetTypeID

Gets the Core Foundation type identifier for the Network Service browser object.

CFNetServiceBrowserSearchForServices

Searches a domain for services of a specified type.

CFNetServiceBrowserStopSearch

Stops a search for domains or services.

CFNetServiceBrowserUnscheduleFromRunLoop

Unschedules a CFNetServiceBrowser from a run loop and mode.

CFNetServiceCancel

Cancels a service registration or a service resolution.

CFNetServiceCreate

Creates an instance of a Network Service object.

CFNetServiceCreateCopy

Creates a copy of a CFNetService object.

CFNetServiceCreateDictionaryWithTXTData

Uses TXT record data to create a dictionary.

CFNetServiceCreateTXTDataWithDictionary

Flattens a set of key/value pairs into a CFDataRef suitable for passing to CFNetServiceSetTXTData.

CFNetServiceGetAddressing

Gets the IP addressing from a CFNetService.

CFNetServiceGetDomain

Gets the domain from a CFNetService.

CFNetServiceGetName

Gets the name from a CFNetService.

CFNetServiceGetPortNumber

This function gets the port number from a CFNetService.

CFNetServiceGetTXTData

Queries a network service for the contents of its TXT records.

CFNetServiceGetTargetHost

Queries a CFNetService for its target hosts.

CFNetServiceGetType

Gets the type from a CFNetService.

CFNetServiceGetTypeID

Gets the Core Foundation type identifier for the Network Service object.

CFNetServiceMonitorCreate

Creates an instance of a NetServiceMonitor object that watches for record changes.

CFNetServiceMonitorGetTypeID

Gets the Core Foundation type identifier for all CFNetServiceMonitor instances.

CFNetServiceMonitorInvalidate

Invalidates an instance of a Network Service monitor object.

CFNetServiceMonitorScheduleWithRunLoop

Schedules a CFNetServiceMonitor on a run loop.

CFNetServiceMonitorStart

Starts monitoring.

CFNetServiceMonitorStop

Stops a CFNetServiceMonitor.

CFNetServiceMonitorUnscheduleFromRunLoop

Unschedules a CFNetServiceMonitor from a run loop.

CFNetServiceRegister

Makes a CFNetService available on the network.

Deprecated
CFNetServiceResolve

This function updates the specified CFNetService with the IP address or addresses associated with the service. Call CFNetServiceGetAddressing to get the addresses.

Deprecated
CFNetServiceResolveWithTimeout

Gets the IP address or addresses for a CFNetService.

CFNetServiceSetClient

Associates a callback function with a CFNetService or disassociates a callback function from a CFNetService.

CFNetServiceSetTXTData

Sets the TXT record for a CFNetService.

CFNetServiceUnscheduleFromRunLoop

Unschedules a CFNetService from a run loop.

CFNetServiceScheduleWithRunLoop

Schedules a CFNetService on a run loop.