iOS Developer Library

Developer

CoreFoundation Framework Reference CFStream Reference

Options
Deployment Target:

On This Page
Language:

CFStream Reference

Inherits From


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import CoreFoundation

Objective-C

@import CoreFoundation;

This document describes the generic CFStream functions, data types, and constants. See also CFReadStreamRef and CFWriteStreamRef for functions and constants specific to read and write streams respectively.

Functions

  • Creates readable and writable streams connected to a socket.

    Declaration

    Swift

    func CFStreamCreatePairWithPeerSocketSignature(_ alloc: CFAllocator!, _ signature: UnsafePointer<CFSocketSignature>, _ readStream: UnsafeMutablePointer<Unmanaged<CFReadStream>?>, _ writeStream: UnsafeMutablePointer<Unmanaged<CFWriteStream>?>)

    Objective-C

    void CFStreamCreatePairWithPeerSocketSignature ( CFAllocatorRef alloc, const CFSocketSignature *signature, CFReadStreamRef *readStream, CFWriteStreamRef *writeStream );

    Parameters

    alloc

    The allocator to use to allocate memory for the new objects. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    signature

    A CFSocketSignature structure identifying the communication protocol and address to which the socket streams should connect.

    readStream

    On return, a readable stream connected to the socket address in signature. If you pass NULL, this function will not create a readable stream. Ownership follows the Create Rule.

    writeStream

    On return, a writable stream connected to the socket address in signature. If you pass NULL, this function will not create a writable stream. Ownership follows the Create Rule.

    Discussion

    The streams do not create a socket or connect to the remote host until you open one of the streams.

    Most properties are shared by both streams. Setting a shared property for one stream automatically sets the property for the other.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later

  • Creates readable and writable streams connected to a TCP/IP port of a particular host.

    Declaration

    Swift

    func CFStreamCreatePairWithSocketToHost(_ alloc: CFAllocator!, _ host: CFString!, _ port: UInt32, _ readStream: UnsafeMutablePointer<Unmanaged<CFReadStream>?>, _ writeStream: UnsafeMutablePointer<Unmanaged<CFWriteStream>?>)

    Objective-C

    void CFStreamCreatePairWithSocketToHost ( CFAllocatorRef alloc, CFStringRef host, UInt32 port, CFReadStreamRef *readStream, CFWriteStreamRef *writeStream );

    Parameters

    alloc

    The allocator to use to allocate memory for the CFReadStream and CFWriteStream objects. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    host

    The hostname to which the socket streams should connect. The host can be specified using an IPv4 or IPv6 address or a fully qualified DNS hostname.

    port

    The TCP port number to which the socket streams should connect.

    readStream

    Upon return, a readable stream connected to the socket address in port. If you pass NULL, this function will not create a readable stream. Ownership follows the Create Rule.

    writeStream

    Upon return, a writable stream connected to the socket address in port. If you pass NULL, this function will not create a writable stream. Ownership follows the Create Rule.

    Discussion

    The streams do not create a socket, resolve the hostname, or connect to the remote host until you open one of the streams.

    Most properties are shared by both streams. Setting a shared property for one stream automatically sets the property for the other.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later

  • Creates readable and writable streams connected to a socket.

    Declaration

    Swift

    func CFStreamCreatePairWithSocket(_ alloc: CFAllocator!, _ sock: CFSocketNativeHandle, _ readStream: UnsafeMutablePointer<Unmanaged<CFReadStream>?>, _ writeStream: UnsafeMutablePointer<Unmanaged<CFWriteStream>?>)

    Objective-C

    void CFStreamCreatePairWithSocket ( CFAllocatorRef alloc, CFSocketNativeHandle sock, CFReadStreamRef *readStream, CFWriteStreamRef *writeStream );

    Parameters

    alloc

    The allocator to use to allocate memory for the new objects. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    sock

    The pre-existing (and already connected) socket which the socket streams should use.

    readStream

    Upon return, a readable stream connected to the socket address in signature. If you pass NULL, this function will not create a readable stream. Ownership follows the Create Rule.

    writeStream

    Upon return, a writable stream connected to the socket address in signature. If you pass NULL, this function will not create a writable stream. Ownership follows the Create Rule.

    Discussion

    Most properties are shared by both streams. Setting a shared property for one stream automatically sets the property for the other.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later

  • Creates a pair of read and write streams.

    Declaration

    Swift

    func CFStreamCreateBoundPair(_ alloc: CFAllocator!, _ readStream: UnsafeMutablePointer<Unmanaged<CFReadStream>?>, _ writeStream: UnsafeMutablePointer<Unmanaged<CFWriteStream>?>, _ transferBufferSize: CFIndex)

    Objective-C

    void CFStreamCreateBoundPair ( CFAllocatorRef alloc, CFReadStreamRef *readStream, CFWriteStreamRef *writeStream, CFIndex transferBufferSize );

    Parameters

    alloc

    The allocator to use to allocate memory for the new objects. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    readStream

    Upon return, a readable stream. Ownership follows the Create Rule.

    writeStream

    Upon return, a writable. Ownership follows the Create Rule.

    transferBufferSize

    The size of the buffer to use to transfer data from readStream to writeStream.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later

Data Types

  • Declaration

    Swift

    struct CFStreamError { var domain: CFIndex var error: Int32 init() init(domain domain: CFIndex, error error: Int32) }

    Objective-C

    typedef struct { CFStreamErrorDomain domain; SInt32 error } CFStreamError;

    Fields

    domain

    The error domain that should be used to interpret the error. See CFStream Error Domain Constants for possible values.

    error

    The error code.

    Availability

    Available in iOS 2.0 and later

  • A structure provided when an application registers itself to receive stream-related events.

    Declaration

    Objective-C

    struct CFStreamClientContext { CFIndex version; void *info; void *(*retain)(void *info); void (*release)(void *info); CFStringRef (*copyDescription)(void *info); } CFStreamClientContext;

    Fields

    version

    An integer of type CFIndex. Currently the only valid value is zero.

    info

    A pointer to allocated memory containing user-defined data that will be valid for as long as the client is registered with the stream. You may assign NULL if your callback function doesn’t want to receive user-defined data.

    retain

    A pointer to a function callback that retains the data pointed to by the info field.You may set this function pointer to NULL.

    release

    A pointer to a function callback that releases the data pointed to by the info field.You may set this function pointer to NULL but doing so might result in memory leaks.

    copyDescription

    A pointer to a function callback that provides a description of the data pointed to by the info field. In implementing this function, return a reference to a CFString object that describes your allocator, particularly some characteristics of your user-defined data. You may set this function pointer to NULL, in which case Core Foundation will provide a rudimentary description.

Constants

  • Constants that describe the status of a stream.

    Declaration

    Swift

    enum CFStreamStatus : CFIndex { case NotOpen case Opening case Open case Reading case Writing case AtEnd case Closed case Error }

    Objective-C

    typedef enum { kCFStreamStatusNotOpen = 0, kCFStreamStatusOpening, kCFStreamStatusOpen, kCFStreamStatusReading, kCFStreamStatusWriting, kCFStreamStatusAtEnd, kCFStreamStatusClosed, kCFStreamStatusError } CFStreamStatus;

    Constants

    • NotOpen

      kCFStreamStatusNotOpen

      The stream is not open for reading or writing.

      Available in iOS 2.0 and later

    • Opening

      kCFStreamStatusOpening

      The stream is being opened for reading or for writing.

      Available in iOS 2.0 and later

    • Open

      kCFStreamStatusOpen

      The stream is open.

      Available in iOS 2.0 and later

    • Reading

      kCFStreamStatusReading

      The stream is being read from.

      Available in iOS 2.0 and later

    • Writing

      kCFStreamStatusWriting

      The stream is being written to.

      Available in iOS 2.0 and later

    • AtEnd

      kCFStreamStatusAtEnd

      There is no more data to read, or no more data can be written.

      Available in iOS 2.0 and later

    • Closed

      kCFStreamStatusClosed

      The stream is closed.

      Available in iOS 2.0 and later

    • Error

      kCFStreamStatusError

      An error occurred on the stream.

      Available in iOS 2.0 and later

    Discussion

    The CFStreamStatus enumeration defines constants that describe the status of a stream. These values are returned by CFReadStreamGetStatus and CFWriteStreamGetStatus.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later

  • Defines constants for values returned in the domain field of the CFStreamError structure.

    These constants are returned by CFReadStreamGetError and CFWriteStreamGetError; use CFReadStreamCopyError and CFWriteStreamCopyError instead.

    Declaration

    Swift

    enum CFStreamErrorDomain : CFIndex { case Custom case POSIX case MacOSStatus }

    Objective-C

    typedef enum { kCFStreamErrorDomainCustom = -1, kCFStreamErrorDomainPOSIX = 1, kCFStreamErrorDomainMacOSStatus, } CFStreamErrorDomain;

    Constants

    • Custom

      kCFStreamErrorDomainCustom

      The error code is a custom error code.

      Available in iOS 2.0 and later

    • POSIX

      kCFStreamErrorDomainPOSIX

      The error code is an error code defined in errno.h.

      Available in iOS 2.0 and later

    • MacOSStatus

      kCFStreamErrorDomainMacOSStatus

      The error is an OSStatus value defined in MacErrors.h.

      Available in iOS 2.0 and later

    Discussion

    These constants indicate how the error code in the error field in the CFStreamError structure should be interpreted.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later

  • Defines constants for values returned in the domain field of the CFStreamError structure.

    Declaration

    Swift

    let kCFStreamErrorDomainNetDB: Int32 let kCFStreamErrorDomainNetServices: Int32 let kCFStreamErrorDomainMach: Int32 let kCFStreamErrorDomainFTP: Int32 let kCFStreamErrorDomainHTTP: Int32 let kCFStreamErrorDomainSOCKS: Int32 let kCFStreamErrorDomainSystemConfiguration: Int32 let kCFStreamErrorDomainSSL: Int32

    Objective-C

    const SInt32 kCFStreamErrorDomainNetDB; const SInt32 kCFStreamErrorDomainNetServices; const SInt32 kCFstreamErrorDomainMach; const SInt32 kCFStreamErrorDomainFTP; const SInt32 kCFStreamErrorDomainHTTP; const int kCFStreamErrorDomainSOCKS; const SInt32 kCFStreamErrorDomainSystemConfiguration; const int kCFStreamErrorDomainSSL;

    Constants

    • kCFStreamErrorDomainNetDB

      kCFStreamErrorDomainNetDB

      The error code is an error code defined in netdb.h.

      Available in iOS 2.0 and later

    • kCFStreamErrorDomainNetServices

      kCFStreamErrorDomainNetServices

      The error code is a CFNetService error code. For details, see the CFNetService Error Constants enumeration.

      Available in iOS 2.0 and later

    • kCFStreamErrorDomainMach

      kCFStreamErrorDomainMach

      The error code is a Mach error code defined in mach/error.h.

      Available in iOS 2.0 and later

    • kCFStreamErrorDomainFTP

      kCFStreamErrorDomainFTP

      The error code is an FTP error code.

      Available in iOS 2.0 and later

    • kCFStreamErrorDomainHTTP

      kCFStreamErrorDomainHTTP

      The error code is an HTTP error code.

      Available in iOS 2.0 and later

    • kCFStreamErrorDomainSOCKS

      kCFStreamErrorDomainSOCKS

      The error code is a SOCKS proxy error.

      Available in iOS 2.0 and later

    • kCFStreamErrorDomainSystemConfiguration

      kCFStreamErrorDomainSystemConfiguration

      The error code is a system configuration error code as defined in System/ConfigurationSystemConfiguration.h.

      Available in iOS 2.0 and later

    • kCFStreamErrorDomainSSL

      kCFStreamErrorDomainSSL

      The error code is an SSL error code as defined in Security/SecureTransport.h.

      Available in iOS 2.0 and later

    Discussion

    These constants indicate how the error code in the error field in the CFStreamError structure should be interpreted.

  • Defines constants for stream-related events.

    Declaration

    Swift

    struct CFStreamEventType : RawOptionSetType { init(_ rawValue: CFOptionFlags) init(rawValue rawValue: CFOptionFlags) static var None: CFStreamEventType { get } static var OpenCompleted: CFStreamEventType { get } static var HasBytesAvailable: CFStreamEventType { get } static var CanAcceptBytes: CFStreamEventType { get } static var ErrorOccurred: CFStreamEventType { get } static var EndEncountered: CFStreamEventType { get } }

    Objective-C

    typedef enum { kCFStreamEventNone = 0, kCFStreamEventOpenCompleted = 1, kCFStreamEventHasBytesAvailable = 2, kCFStreamEventCanAcceptBytes = 4, kCFStreamEventErrorOccurred = 8, kCFStreamEventEndEncountered = 16 } CFStreamEventType;

    Constants

    • None

      kCFStreamEventNone

      No event has occurred.

      Available in iOS 2.0 and later

    • OpenCompleted

      kCFStreamEventOpenCompleted

      The open has completed successfully.

      Available in iOS 2.0 and later

    • HasBytesAvailable

      kCFStreamEventHasBytesAvailable

      The stream has bytes to be read.

      Available in iOS 2.0 and later

    • CanAcceptBytes

      kCFStreamEventCanAcceptBytes

      The stream can accept bytes for writing.

      Available in iOS 2.0 and later

    • ErrorOccurred

      kCFStreamEventErrorOccurred

      An error has occurred on the stream.

      Available in iOS 2.0 and later

    • EndEncountered

      kCFStreamEventEndEncountered

      The end of the stream has been reached.

      Available in iOS 2.0 and later

    Discussion

    This enumeration defines constants for stream-related events.

    Import Statement

    Objective-C

    @import CoreFoundation;

    Swift

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later

  • Stream property names that can be set or copied.

    Declaration

    Swift

    let kCFStreamPropertyDataWritten: CFString! let kCFStreamPropertyAppendToFile: CFString! let kCFStreamPropertyFileCurrentOffset: CFString! let kCFStreamPropertySocketNativeHandle: CFString! let kCFStreamPropertySocketRemoteHostName: CFString! let kCFStreamPropertySocketRemotePortNumber: CFString!

    Objective-C

    const CFStringRef kCFStreamPropertyAppendToFile; const CFStringRef kCFStreamPropertyFileCurrentOffset; const CFStringRef kCFStreamPropertyDataWritten; const CFStringRef kCFStreamPropertySocketNativeHandle; const CFStringRef kCFStreamPropertySocketRemoteHostName; const CFStringRef kCFStreamPropertySocketRemotePortNumber;

    Constants

    • kCFStreamPropertyDataWritten

      kCFStreamPropertyDataWritten

      Value is a CFData object that contains all the bytes written to a writable memory stream. You cannot modify this value.

      Available in iOS 2.0 and later

    • kCFStreamPropertyAppendToFile

      kCFStreamPropertyAppendToFile

      Value is a CFBoolean value that indicates whether to append the written data to a file, if it already exists, rather than to replace its contents.

      You must set this value before opening the writable file stream. The default value is kCFBooleanFalse, indicating that the stream should replace any pre-existing file. You cannot read this value.

      Available in iOS 2.0 and later

    • kCFStreamPropertyFileCurrentOffset

      kCFStreamPropertyFileCurrentOffset

      Value is a CFNumber object containing the current file offset.

      Available in iOS 2.0 and later

    • kCFStreamPropertySocketNativeHandle

      kCFStreamPropertySocketNativeHandle

      Value is a CFData object that contains the native handle for a socket stream—of type CFSocketNativeHandle—to which the socket stream is connected.

      This property is only available for socket streams. You cannot modify this value. You can read this value at any time.

      Available in iOS 2.0 and later

    • kCFStreamPropertySocketRemoteHostName

      kCFStreamPropertySocketRemoteHostName

      Value is a CFString object containing the name of the host to which the socket stream is connected or NULL if unknown.

      You cannot modify this value. You can read this value at any time.]

      Available in iOS 2.0 and later

    • kCFStreamPropertySocketRemotePortNumber

      kCFStreamPropertySocketRemotePortNumber

      Value is a CFNumber object containing the remote port number to which the socket stream is connected or NULL if unknown.

      You cannot modify this value. You can read this value at any time.]

      Available in iOS 2.0 and later

    Discussion

    Use CFReadStreamCopyProperty or CFWriteStreamCopyProperty to read the property values. Use CFReadStreamSetProperty or CFWriteStreamSetProperty to set the property values.