Next Page > Hide TOC

NSPipe Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in Mac OS X v10.0 and later.
Companion guide
Declared in
NSFileHandle.h
Related sample code

Overview

NSPipe objects provide an object-oriented interface for accessing pipes. An NSPipe object represents both ends of a pipe and enables communication through the pipe. A pipe is a one-way communications channel between related processes; one process writes data, while the other process reads that data. The data that passes through the pipe is buffered; the size of the buffer is determined by the underlying operating system. NSPipe is an abstract class, the public interface of a class cluster.

Tasks

Creating an NSPipe Object

Getting the File Handles for a Pipe

Class Methods

pipe

Returns an NSPipe object.

+ (id)pipe

Return Value

An initialized NSPipe object. Returns nil if the method encounters errors while attempting to create the pipe or the NSFileHandle objects that serve as endpoints of the pipe.

Availability
Related Sample Code
Declared In
NSFileHandle.h

Instance Methods

fileHandleForReading

Returns the receiver's read file handle.

- (NSFileHandle *)fileHandleForReading

Return Value

The receiver's read file handle.The descriptor represented by this object is deleted, and the object itself is automatically deallocated when the receiver is deallocated.

Discussion

You use the returned file handle to read from the pipe using NSFileHandle's read methods—availableData, readDataToEndOfFile, and readDataOfLength:.

You don’t need to send closeFile to this object or explicitly release the object after you have finished using it.

Availability
Declared In
NSFileHandle.h

fileHandleForWriting

Returns the receiver's write file handle.

- (NSFileHandle *)fileHandleForWriting

Return Value

The receiver's write file handle. This object is automatically deallocated when the receiver is deallocated.

Discussion

You use the returned file handle to write to the pipe using NSFileHandle's writeData: method. When you are finished writing data to this object, send it a closeFile message to delete the descriptor. Deleting the descriptor causes the reading process to receive an end-of-data signal (an empty NSData object).

Availability
Declared In
NSFileHandle.h

init

Returns an initialized NSPipe object.

- (id)init

Return Value

An initialized NSPipe object. Returns nil if the method encounters errors while attempting to create the pipe or the NSFileHandle objects that serve as endpoints of the pipe.

Availability
See Also
Declared In
NSFileHandle.h

Next Page > Hide TOC


© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-01-26)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.