CFStream Reference
| Framework | CoreFoundation/CoreFoundation.h |
| Declared in | CFFTPStream.h CFHTTPStream.h CFHost.h CFNetServices.h CFSocketStream.h CFStream.h |
| Companion guides |
Overview
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
CFStreamCreateBoundPair
Creates a pair of read and write streams.
void CFStreamCreateBoundPair ( CFAllocatorRef alloc, CFReadStreamRef *readStream, CFWriteStreamRef *writeStream, CFIndex transferBufferSize );
Parameters
- alloc
The allocator to use to allocate memory for the new objects. Pass
NULLorkCFAllocatorDefaultto use the current default allocator.- readStream
Upon return, a readable stream. Ownership follows the Create Rule in Memory Management Programming Guide for Core Foundation.
- writeStream
Upon return, a writable. Ownership follows the Create Rule in Memory Management Programming Guide for Core Foundation.
- transferBufferSize
The size of the buffer to use to transfer data from readStream to writeStream.
Availability
- Available in iOS 2.0 and later.
Declared In
CFStream.hCFStreamCreatePairWithPeerSocketSignature
Creates readable and writable streams connected to a socket.
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
NULLorkCFAllocatorDefaultto use the current default allocator.- signature
A
CFSocketSignaturestructure 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 in Memory Management Programming Guide for Core Foundation.- 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 in Memory Management Programming Guide for Core Foundation.
Discussion
The streams do not open a connection to the socket until one of the streams is opened.
Most properties are shared by both streams. Setting the property for one stream automatically sets the property for the other.
Availability
- Available in iOS 2.0 and later.
Declared In
CFStream.hCFStreamCreatePairWithSocket
Creates readable and writable streams connected to a socket.
void CFStreamCreatePairWithSocket ( CFAllocatorRef alloc, CFSocketNativeHandle sock, CFReadStreamRef *readStream, CFWriteStreamRef *writeStream );
Parameters
- alloc
The allocator to use to allocate memory for the new objects. Pass
NULLorkCFAllocatorDefaultto use the current default allocator.- sock
The pre-existing (and already connected) socket which the socket streams should use.
Important: By default, your app is responsible for closing this socket after you close both streams. If you want CFNetwork to take ownership of the socket, set the
kCFStreamPropertyShouldCloseNativeSocketproperty of the stream tokCFBooleanTrue.- 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 in Memory Management Programming Guide for Core Foundation.- 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 in Memory Management Programming Guide for Core Foundation.
Discussion
Most properties are shared by both streams. Setting the property for one stream automatically sets the property for the other.
Availability
- Available in iOS 2.0 and later.
Declared In
CFStream.hCFStreamCreatePairWithSocketToHost
Creates readable and writable streams connected to a TCP/IP port of a particular host.
void CFStreamCreatePairWithSocketToHost ( CFAllocatorRef alloc, CFStringRef host, UInt32 port, CFReadStreamRef *readStream, CFWriteStreamRef *writeStream );
Parameters
- alloc
The allocator to use to allocate memory for the
CFReadStreamandCFWriteStreamobjects. PassNULLorkCFAllocatorDefaultto use the current default allocator.- host
The host name to which the socket streams should connect. The host can be specified using an IPv4 or IPv6 address or a fully qualified DNS host name.
- 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 in Memory Management Programming Guide for Core Foundation.- 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 in Memory Management Programming Guide for Core Foundation.
Discussion
The streams do not open a connection to the specified host until one of the streams is opened.
Most properties are shared by both streams. Setting the property for one stream automatically sets the property for the other.
Availability
- Available in iOS 2.0 and later.
Declared In
CFStream.hData Types
CFStreamError
The structure returned by CFReadStreamGetError and CFWriteStreamGetError. (Deprecated. Use CFReadStreamCopyError and CFWriteStreamCopyError instead.)
typedef struct {
CFStreamErrorDomain domain;
SInt32 error
} CFStreamError;
Fields
domainThe error domain that should be used to interpret the error. See
CFStream Error Domain Constantsfor possible values.errorThe error code.
Availability
- Available in iOS 2.0 and later.
Declared In
CFStream.hCFStreamClientContext
A structure provided when an application registers itself to receive stream-related events.
struct CFStreamClientContext {
CFIndex version;
void *info;
void *(*retain)(void *info);
void (*release)(void *info);
CFStringRef (*copyDescription)(void *info);
} CFStreamClientContext;
Fields
versionAn integer of type
CFIndex. Currently the only valid value is zero.infoA 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
NULLif your callback function doesn’t want to receive user-defined data.retainA pointer to a function callback that retains the data pointed to by the
infofield.You may set this function pointer toNULL.releaseA pointer to a function callback that releases the data pointed to by the
infofield.You may set this function pointer toNULLbut doing so might result in memory leaks.copyDescriptionA pointer to a function callback that provides a description of the data pointed to by the
infofield. In implementing this function, return a reference to aCFStringobject that describes your allocator, particularly some characteristics of your user-defined data. You may set this function pointer toNULL, in which case Core Foundation will provide a rudimentary description.
Constants
CFStream Status Constants
Constants that describe the status of a stream.
typedef enum {
kCFStreamStatusNotOpen = 0,
kCFStreamStatusOpening,
kCFStreamStatusOpen,
kCFStreamStatusReading,
kCFStreamStatusWriting,
kCFStreamStatusAtEnd,
kCFStreamStatusClosed,
kCFStreamStatusError
} CFStreamStatus;
Constants
kCFStreamStatusNotOpenThe stream is not open for reading or writing.
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamStatusOpeningThe stream is being opened for reading or for writing.
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamStatusOpenThe stream is open.
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamStatusReadingThe stream is being read from.
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamStatusWritingThe stream is being written to.
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamStatusAtEndThere is no more data to read, or no more data can be written.
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamStatusClosedThe stream is closed.
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamStatusErrorAn error occurred on the stream.
Available in iOS 2.0 and later.
Declared in
CFStream.h.
Discussion
The CFStreamStatus enumeration defines constants that describe the status of a stream. These values are returned by CFReadStreamGetStatus and CFWriteStreamGetStatus.
CFStream Error Domain Constants
Defines constants for values returned in the domain field of the CFStreamError structure. (Deprecated. These constants are returned by CFReadStreamGetError and CFWriteStreamGetError; use CFReadStreamCopyError and CFWriteStreamCopyError instead.)
typedef enum {
kCFStreamErrorDomainCustom = -1,
kCFStreamErrorDomainPOSIX = 1,
kCFStreamErrorDomainMacOSStatus,
} CFStreamErrorDomain;
Constants
kCFStreamErrorDomainCustomThe error code is a custom error code.
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamErrorDomainPOSIXThe error code is an error code defined in
errno.h.Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamErrorDomainMacOSStatusThe error is an OSStatus value defined in
MacErrors.h.Available in iOS 2.0 and later.
Declared in
CFStream.h.
Discussion
These constants indicate how the error code in the error field in the CFStreamError structure should be interpreted.
CFStream Error Domain Constants (CFHost)
Defines constants for values returned in the domain field of the CFStreamError structure.
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
kCFStreamErrorDomainNetDBThe error code is an error code defined in
netdb.h.Available in iOS 2.0 and later.
Declared in
CFHost.h.kCFStreamErrorDomainNetServicesThe error code is a
CFNetServiceerror code. For details, see theCFNetService Error Constantsenumeration.Available in iOS 2.0 and later.
Declared in
CFNetServices.h.kCFStreamErrorDomainMachThe error code is a Mach error code defined in
mach/error.h.Available in iOS 2.0 and later.
Declared in
CFNetServices.h.kCFStreamErrorDomainFTPThe error code is an FTP error code.
Available in iOS 2.0 and later.
Declared in
CFFTPStream.h.kCFStreamErrorDomainHTTPThe error code is an HTTP error code.
Available in iOS 2.0 and later.
Declared in
CFHTTPStream.h.kCFStreamErrorDomainSOCKSThe error code is a SOCKS proxy error.
Available in iOS 2.0 and later.
Declared in
CFSocketStream.h.kCFStreamErrorDomainSystemConfigurationThe error code is a system configuration error code as defined in
System/ConfigurationSystemConfiguration.h.Available in iOS 2.0 and later.
Declared in
CFHost.h.kCFStreamErrorDomainSSLThe error code is an SSL error code as defined in
Security/SecureTransport.h.Available in iOS 2.0 and later.
Declared in
CFSocketStream.h.
Discussion
These constants indicate how the error code in the error field in the CFStreamError structure should be interpreted.
CFStream Event Type Constants
Defines constants for stream-related events.
typedef enum {
kCFStreamEventNone = 0,
kCFStreamEventOpenCompleted = 1,
kCFStreamEventHasBytesAvailable = 2,
kCFStreamEventCanAcceptBytes = 4,
kCFStreamEventErrorOccurred = 8,
kCFStreamEventEndEncountered = 16
} CFStreamEventType;
Constants
kCFStreamEventNoneNo event has occurred.
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamEventOpenCompletedThe open has completed successfully.
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamEventHasBytesAvailableThe stream has bytes to be read.
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamEventCanAcceptBytesThe stream can accept bytes for writing.
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamEventErrorOccurredAn error has occurred on the stream.
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamEventEndEncounteredThe end of the stream has been reached.
Available in iOS 2.0 and later.
Declared in
CFStream.h.
Discussion
This enumeration defines constants for stream-related events.
Stream Properties
Stream property names that can be set or copied.
const CFStringRef kCFStreamPropertyAppendToFile; const CFStringRef kCFStreamPropertyFileCurrentOffset; const CFStringRef kCFStreamPropertyDataWritten; const CFStringRef kCFStreamPropertySocketNativeHandle; const CFStringRef kCFStreamPropertySocketRemoteHostName; const CFStringRef kCFStreamPropertySocketRemotePortNumber;
Constants
kCFStreamPropertyDataWrittenValue is a
CFDataobject that contains all the bytes written to a writable memory stream. You cannot modify this value.Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamPropertyAppendToFileValue is a
CFBooleanvalue 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.
Declared in
CFStream.h.kCFStreamPropertyFileCurrentOffsetValue is a
CFNumberobject containing the current file offset.Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamPropertySocketNativeHandleValue is a
CFDataobject that contains the native handle for a socket stream—of typeCFSocketNativeHandle—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.
Declared in
CFStream.h.kCFStreamPropertySocketRemoteHostNameValue is a
CFStringobject containing the name of the host to which the socket stream is connected orNULLif unknown.You cannot modify this value. You can read this value at any time.]
Available in iOS 2.0 and later.
Declared in
CFStream.h.kCFStreamPropertySocketRemotePortNumberValue is a
CFNumberobject containing the remote port number to which the socket stream is connected orNULLif unknown.You cannot modify this value. You can read this value at any time.]
Available in iOS 2.0 and later.
Declared in
CFStream.h.
Discussion
Use CFReadStreamCopyProperty or CFWriteStreamCopyProperty to read the property values. Use CFReadStreamSetProperty or CFWriteStreamSetProperty to set the property values.
© 2013 Apple Inc. All Rights Reserved. (Last updated: 2013-04-23)