Contents

CFNetServiceBrowserCreate(_:_:_:)

Creates an instance of a Network Service browser object.

Declaration

func CFNetServiceBrowserCreate(_ alloc: CFAllocator?, _ clientCB: CFNetServiceBrowserClientCallBack, _ clientContext: UnsafeMutablePointer<CFNetServiceClientContext>) -> Unmanaged<CFNetServiceBrowser>

Parameters

  • alloc:

    The allocator to use to allocate memory for the new object. Pass NULL or Kcfallocatordefault to use the current default allocator.

  • clientCB:

    Callback function that is to be called when domains and services are found; cannot be NULL. For details, see Cfnetservicebrowserclientcallback.

  • clientContext:

    Context information to be used when clientCB is called; cannot be NULL. For details, see Cfnetserviceclientcontext.

Return Value

A new browser object, or NULL if the instance could not be created. Ownership follows the The Create Rule.

Discussion

This function creates an instance of a Network Service browser object, called a CFNetServiceBrowser, that can be used to search for domains and for services.

To use the resulting CFNetServiceBrowser in asynchronous mode, call CFNetServiceBrowserScheduleWithRunLoop(_:_:_:). Then call CFNetServiceBrowserSearchForDomains(_:_:_:) and CFNetServiceBrowserSearchForServices(_:_:_:_:) to use the CFNetServiceBrowser to search for services and domains, respectively. The callback function specified by clientCB is called from a run loop to pass search results to your application. The search continues until you stop the search by calling CFNetServiceBrowserStopSearch(_:_:).

If you do not call CFNetServiceBrowserScheduleWithRunLoop(_:_:_:), searches with the resulting CFNetServiceBrowser are made in synchronous mode. Calls made to CFNetServiceBrowserSearchForDomains(_:_:_:) and CFNetServiceBrowserSearchForServices(_:_:_:_:) block until there are search results, in which case the callback function specified by clientCB is called, until the search is are stopped by calling CFNetServiceBrowserStopSearch(_:_:) from another thread, or an error occurs.

To shut down a CFNetServiceBrowser that is running in asynchronous mode, call CFNetServiceBrowserStopSearch(_:_:), followed by CFNetServiceBrowserUnscheduleFromRunLoop(_:_:_:), and then CFNetServiceBrowserInvalidate(_:).

Special Considerations

This function is thread safe.

See Also

Network Services