CFReadStream

Overview

CFReadStream provides an interface for reading a byte stream either synchronously or asynchronously. You can create streams that read bytes from a block of memory, a file, or a generic socket. All streams need to be opened, using CFReadStreamOpen, before reading.

Use CFWriteStream for writing byte streams. The CFNetwork framework defines an additional type of stream for reading responses to HTTP requests.

CFReadStream is “toll-free bridged” with its Cocoa Foundation counterpart, NSInputStream. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. Therefore, in a method where you see an NSInputStream * parameter, you can pass in a CFReadStreamRef, and in a function where you see a CFReadStreamRef parameter, you can pass in an NSInputStream instance. Note, however, that you may have either a delegate or callbacks but not both. See Toll-Free Bridged Types for more information on toll-free bridging.

Topics

Creating a Read Stream

CFReadStreamCreateWithBytesNoCopy

Creates a readable stream for a block of memory.

CFReadStreamCreateWithFile

Creates a readable stream for a file.

Opening and Closing a Read Stream

CFReadStreamClose

Closes a readable stream.

CFReadStreamOpen

Opens a stream for reading.

Reading from a Stream

CFReadStreamRead

Reads data from a readable stream.

Scheduling a Read Stream

CFReadStreamScheduleWithRunLoop

Schedules a stream into a run loop.

CFReadStreamUnscheduleFromRunLoop

Removes a read stream from a given run loop.

Examining Stream Properties

CFReadStreamCopyProperty

Returns the value of a property for a stream.

CFReadStreamGetBuffer

Returns a pointer to a stream’s internal buffer of unread data, if possible.

CFReadStreamCopyError

Returns the error associated with a stream.

CFReadStreamGetError

Returns the error status of a stream.

CFReadStreamGetStatus

Returns the current state of a stream.

CFReadStreamHasBytesAvailable

Returns a Boolean value that indicates whether a readable stream has data that can be read without blocking.

Setting Stream Properties

CFReadStreamSetClient

Assigns a client to a stream, which receives callbacks when certain events occur.

CFReadStreamSetProperty

Sets the value of a property for a stream.

Getting the CFReadStream Type ID

CFReadStreamGetTypeID

Returns the type identifier the CFReadStream opaque type.

Callbacks

CFReadStreamClientCallBack

Callback invoked when certain types of activity takes place on a readable stream.

Data Types

CFReadStreamRef

A reference to a readable stream object.

CFStreamClientContext

A structure that contains program-defined data and callbacks with which you can configure a stream’s client behavior.

See Also

Opaque Types

CFFileDescriptor

The CFFileDescriptor provides an opaque type to monitor file descriptors for read and write activity via CFRunLoop.

CFStringTokenizer

CFStringTokenizer allows you to tokenize strings into words, sentences or paragraphs in a language-neutral way. It supports languages such as Japanese and Chinese that do not delimit words by spaces, as well as de-compounding German compounds. You can obtain Latin transcription for tokens. It also provides language identification API.