iOS Developer Library

Developer

Core Foundation Framework Reference CFStream Reference

Options
Deployment Target:

On This Page
Language:

CFStream Reference

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.

  • Creates readable and writable streams connected to a given CFHost object.

    Declaration

    Swift

    func CFStreamCreatePairWithSocketToCFHost(_ alloc: CFAllocator?, _ host: CFHost, _ port: Int32, _ readStream: UnsafeMutablePointer<Unmanaged<CFReadStream>?>, _ writeStream: UnsafeMutablePointer<Unmanaged<CFWriteStream>?>)

    Objective-C

    void CFStreamCreatePairWithSocketToCFHost ( CFAllocatorRef alloc, CFHostRef host, SInt32 port, CFReadStreamRef _Nullable *readStream, CFWriteStreamRef _Nullable *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

    A CFHost object to which the streams are connected. If unresolved, the host will be resolved prior to connecting.

    port

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

    readStream

    Upon return, contains a CFReadStream object connected to the host host on port port, or NULL if there is a failure during creation. If you pass NULL, the function will not create a readable stream. Ownership follows the Create Rule.

    writeStream

    Upon return, contains a CFWriteStream object connected to the host host on port port, or NULL if there is a failure during creation. If you pass NULL, the function will not create a writable stream. Ownership follows the Create Rule.

    Discussion

    The streams do not create a socket or connect to the specified 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.

    Availability

    Available in iOS 2.0 and later.

  • Creates a pair of streams for a CFNetService.

    Declaration

    Swift

    func CFStreamCreatePairWithSocketToNetService(_ alloc: CFAllocator?, _ service: CFNetService, _ readStream: UnsafeMutablePointer<Unmanaged<CFReadStream>?>, _ writeStream: UnsafeMutablePointer<Unmanaged<CFWriteStream>?>)

    Objective-C

    void CFStreamCreatePairWithSocketToNetService ( CFAllocatorRef alloc, CFNetServiceRef service, CFReadStreamRef _Nullable *readStream, CFWriteStreamRef _Nullable *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.

    service

    Reference to the CFNetService to which the streams are to be connected. If the service is not resolved, the service will be resolved before the streams are connected.

    readstream

    Upon return, contains a CFReadStream object connected to the service specified by service, or NULL if there is a failure during creation. If you pass NULL, the function will not create a readable stream. Ownership follows the Create Rule.

    writeStream

    Upon return, contains a CFWriteStream object connected to the service specified by service, or NULL if there is a failure during creation. If you pass NULL, the function will not create a writable stream. Ownership follows the Create Rule.

    Discussion

    The streams do not create a socket, resolve the service, or connect to the service’s 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.

    Special Considerations

    This function is thread safe.

    Availability

    Available in iOS 2.0 and later.

  • This function gets error codes in the kCFStreamErrorDomainSOCKS domain from the CFStreamError returned by a stream operation.

    Declaration

    Swift

    func CFSocketStreamSOCKSGetError(_ error: UnsafePointer<CFStreamError>) -> Int32

    Objective-C

    SInt32 CFSocketStreamSOCKSGetError ( const CFStreamError *error );

    Parameters

    error

    The error value to decode.

    Discussion

    Error codes in the kCFStreamErrorDomainSOCKS domain can come from multiple parts of the protocol stack, many of which define their own error values as part of outside specifications such as the HTTP specification.

    To avoid confusion from conflicting error numbers, error codes in the kCFStreamErrorDomainSOCKS domain contain two parts: a subdomain, which tells which part of the protocol stack generated the error, and the error code itself.

    Calling CFSocketStreamSOCKSGetError returns the error code itself, which must be interpreted in the context of the result of a call to CFSocketStreamSOCKSGetErrorSubdomain. Possible return values (beyond subdomain-specific values such as client versions and HTTP error codes) are listed in CFStream Errors.

    Availability

    Available in iOS 2.0 and later.

  • Gets the error subdomain associated with errors in the kCFStreamErrorDomainSOCKS domain from the CFStreamError returned by a stream operation.

    Declaration

    Swift

    func CFSocketStreamSOCKSGetErrorSubdomain(_ error: UnsafePointer<CFStreamError>) -> Int32

    Objective-C

    SInt32 CFSocketStreamSOCKSGetErrorSubdomain ( const CFStreamError *error );

    Parameters

    error

    The error value to decode.

    Discussion

    Error codes in the kCFStreamErrorDomainSOCKS domain can come from multiple parts of the protocol stack, many of which define their own error values as part of outside specifications such as the HTTP specification.

    To avoid confusion from conflicting error numbers, error codes in the kCFStreamErrorDomainSOCKS domain contain two parts: a subdomain, which tells which part of the protocol stack generated the error, and the error code itself.

    Calling CFSocketStreamSOCKSGetErrorSubdomain returns an identifier that tells which layer of the protocol stack produced the error. The possible values are listed in Data Types. With this information, you can interpret the error codes returned by CFSocketStreamSOCKSGetError.

    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 kCFStreamErrorDomainSystemConfiguration: Int32 let kCFStreamErrorDomainWinSock: CFIndex let kCFStreamErrorDomainSOCKS: Int32 let kCFStreamErrorDomainSSL: Int32

    Objective-C

    const SInt32 kCFStreamErrorDomainNetDB; const SInt32 kCFStreamErrorDomainNetServices; const SInt32 kCFstreamErrorDomainMach; const SInt32 kCFStreamErrorDomainFTP; const SInt32 kCFStreamErrorDomainHTTP; const SInt32 kCFStreamErrorDomainSystemConfiguration; const CFIndex kCFStreamErrorDomainWinSock; const int kCFStreamErrorDomainSOCKS; 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.

    • kCFStreamErrorDomainSystemConfiguration

      kCFStreamErrorDomainSystemConfiguration

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

      Available in iOS 2.0 and later.

    • kCFStreamErrorDomainWinSock

      kCFStreamErrorDomainWinSock

      When running CFNetwork code on Windows, this domain returns error codes associated with the underlying TCP/IP stack. You should also note that non-networking errors such as ENOMEM are delivered through the POSIX domain. See the header winsock2.h for relevant error codes.

      Available in iOS 2.0 and later.

    • kCFStreamErrorDomainSOCKS

      kCFStreamErrorDomainSOCKS

      The error code is a SOCKS proxy error.

      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.

  • Subdomains used to determine how to interpret an error in the kCFStreamErrorDomainSOCKS domain.

    Declaration

    Objective-C

    enum { kCFStreamErrorSOCKSSubDomainNone = 0, kCFStreamErrorSOCKSSubDomainVersionCode = 1, kCFStreamErrorSOCKS4SubDomainResponse = 2, kCFStreamErrorSOCKS5SubDomainUserPass = 3, kCFStreamErrorSOCKS5SubDomainMethod = 4, kCFStreamErrorSOCKS5SubDomainResponse = 5 };

    Constants

    • kCFStreamErrorSOCKSSubDomainNone

      The error code returned is a SOCKS error number.

    • kCFStreamErrorSOCKSSubDomainVersionCode

      The error returned contains the version of SOCKS that the server wishes to use.

    • kCFStreamErrorSOCKS4SubDomainResponse

      The error returned is the status code that the server returned after the last operation.

    • kCFStreamErrorSOCKS5SubDomainUserPass

      This subdomain returns error codes associated with the last authentication attempt.

    • kCFStreamErrorSOCKS5SubDomainMethod

      This subdomain returns the server’s desired negotiation method.

    • kCFStreamErrorSOCKS5SubDomainResponse

      This subdomain returns the response code sent by the server when replying to a connection request.

    Discussion

    Error codes in the kCFStreamErrorDomainSOCKS domain can come from multiple parts of the protocol stack, many of which define their own error values as part of outside specifications such as the HTTP specification.

    To avoid confusion from conflicting error numbers, error codes in the kCFStreamErrorDomainSOCKS domain contain two parts: a subdomain, which tells which part of the protocol stack generated the error, and the error code itself.

    Calling CFSocketStreamSOCKSGetErrorSubdomain returns an identifier that tells which layer of the protocol stack produced the error. This list of constants contains the possible values that this function will return.

    Calling CFSocketStreamSOCKSGetError returns the actual error code that the subdomain describes.

  • Error codes returned by the kCFStreamErrorDomainSOCKS error domain.

    Declaration

    Swift

    var kCFStreamErrorSOCKS5BadResponseAddr: Int { get } var kCFStreamErrorSOCKS5BadState: Int { get } var kCFStreamErrorSOCKSUnknownClientVersion: Int { get } var kCFStreamErrorSOCKS4RequestFailed: Int { get } var kCFStreamErrorSOCKS4IdentdFailed: Int { get } var kCFStreamErrorSOCKS4IdConflict: Int { get } var kSOCKS5NoAcceptableMethod: Int { get }

    Objective-C

    /* kCFStreamErrorSOCKSSubDomainNone */ enum { kCFStreamErrorSOCKS5BadResponseAddr = 1, kCFStreamErrorSOCKS5BadState = 2, kCFStreamErrorSOCKSUnknownClientVersion = 3 }; /* kCFStreamErrorSOCKS4SubDomainResponse */ enum { kCFStreamErrorSOCKS4RequestFailed = 91, kCFStreamErrorSOCKS4IdentdFailed = 92, kCFStreamErrorSOCKS4IdConflict = 93 }; /* kCFStreamErrorSOCKS5SubDomainMethod */ enum { kSOCKS5NoAcceptableMethod = 0xFF };

    Constants

    • kCFStreamErrorSOCKS5BadResponseAddr

      kCFStreamErrorSOCKS5BadResponseAddr

      The address returned is not of a known type. This error code is only valid for errors in the kCFStreamErrorSOCKSSubDomainNone subdomain.

      Available in iOS 2.0 and later.

    • kCFStreamErrorSOCKS5BadState

      kCFStreamErrorSOCKS5BadState

      The stream is not in a state that allows the requested operation. This error code is only valid for errors in the kCFStreamErrorSOCKSSubDomainNone subdomain..

      Available in iOS 2.0 and later.

    • kCFStreamErrorSOCKSUnknownClientVersion

      kCFStreamErrorSOCKSUnknownClientVersion

      The SOCKS server rejected access because it does not support connections with the requested SOCKS version. SOCKS client version. You can query the kCFSOCKSVersionKey key to find out what version the server requested. This error code is only valid for errors in the kCFStreamErrorSOCKSSubDomainNone subdomain.

      Available in iOS 2.0 and later.

    • kCFStreamErrorSOCKS4RequestFailed

      kCFStreamErrorSOCKS4RequestFailed

      Request rejected by the server or request failed. This error is specific to SOCKS4. This error code is only valid for errors in the kCFStreamErrorSOCKS4SubDomainResponse subdomain.

      Available in iOS 2.0 and later.

    • kCFStreamErrorSOCKS4IdentdFailed

      kCFStreamErrorSOCKS4IdentdFailed

      Request rejected by the server because it could not connect to the identd daemon on the client. This error is specific to SOCKS4. This error code is only valid for errors in the kCFStreamErrorSOCKS4SubDomainResponse subdomain.

      Available in iOS 2.0 and later.

    • kCFStreamErrorSOCKS4IdConflict

      kCFStreamErrorSOCKS4IdConflict

      Request rejected by the server because the client program and the identd daemon reported different user IDs. This error is specific to SOCKS4. This error code is only valid for errors in the kCFStreamErrorSOCKS4SubDomainResponse subdomain.

      Available in iOS 2.0 and later.

    • kSOCKS5NoAcceptableMethod

      kSOCKS5NoAcceptableMethod

      The client and server could not find a mutually agreeable authentication method. This error code is only valid for errors in the kCFStreamErrorSOCKS5SubDomainMethod subdomain.

      Available in iOS 2.0 and later.

    Discussion

    Error codes in the kCFStreamErrorDomainSOCKS domain can come from multiple parts of the protocol stack, many of which define their own error values as part of outside specifications such as the HTTP specification.

    To avoid confusion from conflicting error numbers, error codes in the kCFStreamErrorDomainSOCKS domain contain two parts: a subdomain, which tells which part of the protocol stack generated the error, and the error code itself.

    Calling CFSocketStreamSOCKSGetErrorSubdomain returns an identifier that tells which layer of the protocol stack produced the error.

    Calling CFSocketStreamSOCKSGetError returns the actual error code that the subdomain describes. This list of constants contains the possible values that this function will return. They must be interpreted within the context of the relevant error subdomain.

  • Defines constants for stream-related events.

    Declaration

    Swift

    struct CFStreamEventType : OptionSetType { 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 kCFStreamPropertyAppendToFile: CFString! let kCFStreamPropertyDataWritten: CFString! let kCFStreamPropertyFileCurrentOffset: CFString! let kCFStreamPropertySocketNativeHandle: CFString! let kCFStreamPropertySocketRemoteHostName: CFString! let kCFStreamPropertySocketRemotePortNumber: CFString! let kCFStreamPropertyShouldCloseNativeSocket: CFString let kCFStreamPropertySocketSecurityLevel: CFString let kCFStreamPropertySSLPeerTrust: CFString let kCFStreamPropertySSLSettings: CFString let kCFStreamPropertySSLContext: CFString let kCFStreamPropertySOCKSProxy: CFString let kCFStreamPropertyProxyLocalBypass: CFString let kCFStreamPropertySocketRemoteHost: CFString let kCFStreamPropertySocketRemoteNetService: CFString let kCFStreamNetworkServiceType: CFString let kCFStreamPropertyConnectionIsCellular: CFString let kCFStreamPropertyNoCellular: CFString

    Objective-C

    const CFStringRef kCFStreamPropertyAppendToFile; const CFStringRef kCFStreamPropertyDataWritten; const CFStringRef kCFStreamPropertyFileCurrentOffset; const CFStringRef kCFStreamPropertySocketNativeHandle; const CFStringRef kCFStreamPropertySocketRemoteHostName; const CFStringRef kCFStreamPropertySocketRemotePortNumber; const CFStringRef kCFStreamPropertyShouldCloseNativeSocket; const CFStringRef kCFStreamPropertySocketSecurityLevel; const CFStringRef kCFStreamPropertySSLPeerCertificates; const CFStringRef kCFStreamPropertySSLPeerTrust; const CFStringRef kCFStreamPropertySSLSettings; const CFStringRef kCFStreamPropertySSLContext; const CFStringRef kCFStreamPropertySOCKSProxy; const CFStringRef kCFStreamPropertyProxyLocalByPass; const CFStringRef kCFStreamPropertySocketRemoteHost; const CFStringRef kCFStreamPropertySocketRemoteNetService; const CFStringRef kCFStreamNetworkServiceType; const CFStringRef kCFStreamPropertyConnectionIsCellular; const CFStringRef kCFStreamPropertyNoCellular;

    Constants

    • 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.

    • 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.

    • 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.

    • kCFStreamPropertyShouldCloseNativeSocket

      kCFStreamPropertyShouldCloseNativeSocket

      Should Close Native Socket property key.

      If set to kCFBooleanTrue, the stream will close and release the underlying native socket when the stream is released. If set to kCFBooleanFalse, the stream will not close and release the underlying native socket when the stream is released. If a stream is created with a native socket, the default value of this property is kCFBooleanFalse. This property is only available for socket streams. It can be set by calling CFReadStreamSetProperty and CFWriteStreamSetProperty, and it can be copied by CFReadStreamCopyProperty and CFWriteStreamCopyProperty.

      Available in iOS 2.0 and later.

    • kCFStreamPropertySocketSecurityLevel

      kCFStreamPropertySocketSecurityLevel

      Socket Security Level property key.

      See CFStream Socket Security Level Constants for specific security level constants to use.

      Available in iOS 2.0 and later.

    • kCFStreamPropertySSLPeerCertificates

      SSL Peer Certificates property key for copy operations, which return a CFArray object containing SecCertificateRef objects.

      For more information, see SSLGetPeerCertificates in Security/SecureTransport.h.

      Available in iOS 2.0 and later.

      Deprecated in iOS 4.0.

    • kCFStreamPropertySSLPeerTrust

      kCFStreamPropertySSLPeerTrust

      SSL Peer Trust property key for copy operations, which return a SecTrustRef object containing the result of the SSL handshake.

      For more information, see SSLCopyPeerTrust in Security/SecureTransport.h.

      Available in iOS 2.0 and later.

    • kCFStreamPropertySSLSettings

      kCFStreamPropertySSLSettings

      SSL Settings property key for set operations.

      The key’s value is a CFDictionary object containing security settings. For information on the dictionary’s keys and values, see CFStream Property SSL Settings Constants. By default, there are no security settings.

      Available in iOS 2.0 and later.

    • kCFStreamPropertySSLContext

      kCFStreamPropertySSLContext

      The SSLContextRef object used for read and write operations on a stream.

      Before opening a stream, you can copy the object from this property and configure it using the Secure Transport API. You can also set this property to specify a new SSLContextRef for a stream. The behavior depends on whether the stream has been opened and on whether an SSL context is associated with the stream, as follows:

      • If the stream has not been opened, the specified object replaces any existing context, and is used in the initial stream handshake when the connection is opened.

      • If the stream has been opened without SSL enabled, setting this property initiates an SSL handshake over the existing socket.

      • After the initial SSL handshake occurs, changing the context object is unsupported.

      If an SSL settings dictionary is set for the kCFStreamPropertySSLSettings key, an SSLContextRef object is created internally and configured based on that dictionary. However, if an SSLContextRef object is set afterwards, its configuration takes precedence over the previously configured context.

      Available in iOS 5.0 and later.

    • kCFStreamPropertySOCKSProxy

      kCFStreamPropertySOCKSProxy

      SOCKS proxy property key.

      To set a CFStream object to use a SOCKS proxy, call CFReadStreamSetProperty or CFWriteStreamSetProperty with the property name set to kCFStreamPropertySOCKSProxy and its value set to a CFDictionary object having at minimum a kCFStreamPropertySOCKSProxyHost key and a kCFStreamPropertySOCKSProxyPort key. For information on these keys, see CFStream SOCKS Proxy Key Constants. SystemConfiguration returns a CFDictionary for SOCKS proxies that is usable without modification.

      Available in iOS 2.0 and later.

    • kCFStreamPropertyProxyLocalBypass

      kCFStreamPropertyProxyLocalBypass

      Proxy Local Bypass property key.

      The key’s value is CFBoolean object whose value indicates whether local hostnames should be subject to proxy handling.

      Available in iOS 2.0 and later.

    • kCFStreamPropertySocketRemoteHost

      kCFStreamPropertySocketRemoteHost

      The key’s value is a CFHostRef for the remote host if it is known. If not, its value is NULL.

      Available in iOS 2.0 and later.

    • kCFStreamPropertySocketRemoteNetService

      kCFStreamPropertySocketRemoteNetService

      The key’s value is a CFNetServiceRef for the remote network service if it is known. If not, its value is NULL.

      Available in iOS 2.0 and later.

    • kCFStreamNetworkServiceType

      kCFStreamNetworkServiceType

      The type of service for the stream. Providing the service type allows the system to properly handle certain attributes of the stream, including routing and suspension behavior. Most streams do not need to set this property. See Stream Service Types for a list of possible values.

      Available in iOS 4.0 and later.

    • kCFStreamPropertyConnectionIsCellular

      kCFStreamPropertyConnectionIsCellular

      A boolean value indicating whether the stream is connected over a cellular (WWAN) interface. This is a read-only property, and is false until the connection has been established.

      Available in iOS 6.0 and later.

    • kCFStreamPropertyNoCellular

      kCFStreamPropertyNoCellular

      A boolean value indicating that the connection should not be established over a cellular (WWAN) connection. This value can be set only before you open the stream.

      Available in iOS 5.0 and later.

    Discussion

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

  • Constants for use in a CFDictionary object that is the value of the kCFStreamPropertySSLSettings stream property key.

    Declaration

    Swift

    let kCFStreamSSLLevel: CFString let kCFStreamSSLValidatesCertificateChain: CFString let kCFStreamSSLPeerName: CFString let kCFStreamSSLCertificates: CFString let kCFStreamSSLIsServer: CFString

    Objective-C

    const CFStringRef kCFStreamSSLLevel; const CFStringRef kCFStreamSSLAllowsExpiredCertificates; const CFStringRef kCFStreamSSLAllowsExpiredRoots; const CFStringRef kCFStreamSSLAllowsAnyRoot; const CFStringRef kCFStreamSSLValidatesCertificateChain; const CFStringRef kCFStreamSSLPeerName; const CFStringRef kCFStreamSSLCertificates; const CFStringRef kCFStreamSSLIsServer;

    Constants

    • kCFStreamSSLLevel

      kCFStreamSSLLevel

      Security property key whose value specifies the stream’s security level.

      By default, a stream’s security level is kCFStreamSocketSecurityLevelNegotiatedSSL. For other possible values, see CFStream Socket Security Level Constants.

      Available in iOS 2.0 and later.

    • kCFStreamSSLAllowsExpiredCertificates

      Security property key whose value indicates whether expired certificates are allowed.

      By default, the value of this key is kCFBooleanFalse (expired certificates are not allowed).

      Available in iOS 2.0 and later.

      Deprecated in iOS 4.0.

    • kCFStreamSSLAllowsExpiredRoots

      Security property whose value indicates whether expired root certificates are allowed.

      By default, the value of this key is kCFBooleanFalse (expired root certificates are not allowed).

      Available in iOS 2.0 and later.

      Deprecated in iOS 4.0.

    • kCFStreamSSLAllowsAnyRoot

      Security property key whose value indicates whether root certificates should be allowed.

      By default, the value of this key is kCFBooleanFalse (root certificates are not allowed).

      Available in iOS 2.0 and later.

      Deprecated in iOS 4.0.

    • kCFStreamSSLValidatesCertificateChain

      kCFStreamSSLValidatesCertificateChain

      Security property key whose value indicates whether the certificate chain should be validated.

      By default, the value of this key is kCFBooleanTrue (the certificate chain should be validated).

      Available in iOS 2.0 and later.

    • kCFStreamSSLPeerName

      kCFStreamSSLPeerName

      Security property key whose value overrides the name used for certificate verification.

      By default, the host name that was used when the stream was created is used; if no host name was used, no peer name will be used. Set the value of this key to kCFNull to prevent name verification.

      Available in iOS 2.0 and later.

    • kCFStreamSSLCertificates

      kCFStreamSSLCertificates

      Security property key whose value is a CFArray of SecCertificateRefs except for the first element in the array, which is a SecIdentityRef.

      For more information, see SSLSetCertificate() in Security/SecureTransport.h.

      Available in iOS 2.0 and later.

    • kCFStreamSSLIsServer

      kCFStreamSSLIsServer

      Security property key whose value indicates whether the connection is to act as a server in the SSL process.

      By default, the value of this key is kCFBooleanFalse (the connection is not to act as a server). If the value of this key is kCFBooleanTrue, the kCFStreamSSLCertificates key must contain a valid value.

      Available in iOS 2.0 and later.

    Discussion

    This enumeration defines the constants for keys in a CFDictionary object that is the value of the kCFStreamPropertySSLSettings key.

  • Constants for setting the security level of a socket stream.

    Declaration

    Swift

    let kCFStreamSocketSecurityLevelNone: CFString let kCFStreamSocketSecurityLevelSSLv2: CFString let kCFStreamSocketSecurityLevelSSLv3: CFString let kCFStreamSocketSecurityLevelTLSv1: CFString let kCFStreamSocketSecurityLevelNegotiatedSSL: CFString

    Objective-C

    const CFStringRef kCFStreamSocketSecurityLevelNone; const CFStringRef kCFStreamSocketSecurityLevelSSLv2; const CFStringRef kCFStreamSocketSecurityLevelSSLv3; const CFStringRef kCFStreamSocketSecurityLevelTLSv1; const CFStringRef kCFStreamSocketSecurityLevelNegotiatedSSL;

    Constants

    • kCFStreamSocketSecurityLevelNone

      kCFStreamSocketSecurityLevelNone

      Specifies that no security level be set.

      Available in iOS 2.0 and later.

    • kCFStreamSocketSecurityLevelSSLv2

      kCFStreamSocketSecurityLevelSSLv2

      Specifies that SSL version 2 be set as the security protocol for a socket stream.

      Available in iOS 2.0 and later.

    • kCFStreamSocketSecurityLevelSSLv3

      kCFStreamSocketSecurityLevelSSLv3

      Specifies that SSL version 3 be set as the security protocol for a socket stream pair.

      If SSL version 3 is not available, specifies that SSL version 2 be set as the security protocol for a socket stream.

      Available in iOS 2.0 and later.

    • kCFStreamSocketSecurityLevelTLSv1

      kCFStreamSocketSecurityLevelTLSv1

      Specifies that TLS version 1 be set as the security protocol for a socket stream.

      Available in iOS 2.0 and later.

    • kCFStreamSocketSecurityLevelNegotiatedSSL

      kCFStreamSocketSecurityLevelNegotiatedSSL

      Specifies that the highest level security protocol that can be negotiated be set as the security protocol for a socket stream.

      Available in iOS 2.0 and later.

    Discussion

    This enumeration defines the preferred constants for setting the security protocol for a socket stream pair when calling CFReadStreamSetProperty or CFWriteStreamSetProperty.

  • Constants for SOCKS Proxy CFDictionary keys.

    Declaration

    Swift

    let kCFStreamPropertySOCKSProxyHost: CFString let kCFStreamPropertySOCKSProxyPort: CFString let kCFStreamPropertySOCKSVersion: CFString let kCFStreamSocketSOCKSVersion4: CFString let kCFStreamSocketSOCKSVersion5: CFString let kCFStreamPropertySOCKSUser: CFString let kCFStreamPropertySOCKSPassword: CFString

    Objective-C

    const CFStringRef kCFStreamPropertySOCKSProxyHost; const CFStringRef kCFStreamPropertySOCKSProxyPort; const CFStringRef kCFStreamPropertySOCKSVersion; const CFStringRef kCFStreamSocketSOCKSVersion4; const CFStringRef kCFStreamSocketSOCKSVersion5; const CFStringRef kCFStreamPropertySOCKSUser; const CFStringRef kCFStreamPropertySOCKSPassword;

    Constants

    • kCFStreamPropertySOCKSProxyHost

      kCFStreamPropertySOCKSProxyHost

      Constant for the SOCKS proxy host key.

      This key contains a CFString object that represents the SOCKS proxy host. Defined to match kSCPropNetProxiesSOCKSProxy.

      Available in iOS 2.0 and later.

    • kCFStreamPropertySOCKSProxyPort

      kCFStreamPropertySOCKSProxyPort

      Constant for the SOCKS proxy host port key.

      This key contains a CFNumberRef object of type kCFNumberSInt32Type whose value represents the port on which the proxy listens.

      Available in iOS 2.0 and later.

    • kCFStreamPropertySOCKSVersion

      kCFStreamPropertySOCKSVersion

      Constant for the SOCKS version key.

      Its value must be kCFStreamSocketSOCKSVersion4 or kCFStreamSocketSOCKSVersion5 to set SOCKS4 or SOCKS5, respectively. If this key is not present, SOCKS5 is used by default.

      Available in iOS 2.0 and later.

    • kCFStreamSocketSOCKSVersion4

      kCFStreamSocketSOCKSVersion4

      Constant used in the kCFStreamSockerSOCKSVersion key to specify SOCKS4 as the SOCKS version for the stream.

      Available in iOS 2.0 and later.

    • kCFStreamSocketSOCKSVersion5

      kCFStreamSocketSOCKSVersion5

      Constant used in the kCFStreamSOCKSVersion key to specify SOCKS5 as the SOCKS version for the stream.

      Available in iOS 2.0 and later.

    • kCFStreamPropertySOCKSUser

      kCFStreamPropertySOCKSUser

      Constant for the key required to set a user name.

      The value is a CFString object containing the user’s name.

      Available in iOS 2.0 and later.

    • kCFStreamPropertySOCKSPassword

      kCFStreamPropertySOCKSPassword

      Constant for the key required to set a user’s password.

      The value is a CFString object containing the user’s password.

      Available in iOS 2.0 and later.

    Discussion

    When setting the stream's SOCKS Proxy property, the property’s value is a CFDictionary object containing at minimum the kCFStreamPropertySOCKSProxyHost and kCFStreamPropertySOCKSProxyPort keys. The dictionary may also contain the other keys described in this section.

  • String constants that specify the service type of a stream.

    Declaration

    Swift

    let kCFStreamNetworkServiceTypeVoIP: CFString let kCFStreamNetworkServiceTypeVideo: CFString let kCFStreamNetworkServiceTypeBackground: CFString let kCFStreamNetworkServiceTypeVoice: CFString

    Objective-C

    CFStringRef const kCFStreamNetworkServiceTypeVoIP; const CFStringRef kCFStreamNetworkServiceTypeVideo; const CFStringRef kCFStreamNetworkServiceTypeBackground; const CFStringRef kCFStreamNetworkServiceTypeVoice;

    Constants

    • kCFStreamNetworkServiceTypeVoIP

      kCFStreamNetworkServiceTypeVoIP

      Specifies that the stream is providing VoIP service.

      Available in iOS 4.0 and later.

      Deprecated in iOS 9.0.

    • kCFStreamNetworkServiceTypeVideo

      kCFStreamNetworkServiceTypeVideo

      Specifies that the stream is providing interactive video data.

      Available in iOS 5.0 and later.

    • kCFStreamNetworkServiceTypeBackground

      kCFStreamNetworkServiceTypeBackground

      Specifies that the stream is a background download.

      Available in iOS 5.0 and later.

    • kCFStreamNetworkServiceTypeVoice

      kCFStreamNetworkServiceTypeVoice

      Specifies that the stream is providing interactive voice data.

      Available in iOS 5.0 and later.

  • Specifies constants for setting the security protocol for a socket stream.

    Declaration

    Objective-C

    typedef enum { kCFStreamSocketSecurityNone = 0, kCFStreamSocketSecuritySSLv2, kCFStreamSocketSecuritySSLv3, kCFStreamSocketSecuritySSLv23, kCFStreamSocketSecurityTLSv1 } CFStreamSocketSecurityProtocol;

    Constants

    • kCFStreamSocketSecurityNone

      Specifies that no security protocol be set for a socket stream.

      Use kCFStreamSocketSecurityLevelNone.

      Available in iOS 2.0 through iOS 7.1.

    • kCFStreamSocketSecuritySSLv2

      Specifies that SSL version 2 be set as the security protocol for a socket stream.

      Use kCFStreamSocketSecurityLevelSSLv2.

      Available in iOS 2.0 through iOS 7.1.

    • kCFStreamSocketSecuritySSLv3

      Specifies that SSL version 3 be set as the security protocol for a socket stream.

      Use kCFStreamSocketSecurityLevelSSLv3.

      Available in iOS 2.0 through iOS 7.1.

    • kCFStreamSocketSecuritySSLv23

      Specifies that SSL version 3 be set as the security protocol for a socket stream pair. If that version is not available, specifies that SSL version 2 be set as the security protocol for a socket stream.

      Use kCFStreamSocketSecurityLevelNegotiatedSSL.

      Available in iOS 2.0 through iOS 7.1.

    • kCFStreamSocketSecurityTLSv1

      Specifies that TLS version 1 be set as the security protocol for a socket stream.

      Use kCFStreamSocketSecurityLevelTLSv1.

      Available in iOS 2.0 through iOS 7.1.

    Discussion

    This enumeration defines constants for setting the security protocol for a socket stream pair when calling CFSocketStreamPairSetSecurityProtocol.

    Import Statement

    Objective-C

    @import CFNetwork;

    Availability

    Available in iOS 2.0 through iOS 7.1.