Skip to content

Commit

Permalink
NSStream additions
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22496 72102866-910b-0410-8b05-ffd578937521
  • Loading branch information
rfm committed Feb 15, 2006
1 parent c91bf05 commit 5f07403
Show file tree
Hide file tree
Showing 10 changed files with 2,503 additions and 1 deletion.
15 changes: 15 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
2006-02-15 Derek Zhou <dzhou@nvidea.com> Richard Frith-Macdonald <rfm@gnu.org>

* Headers/Foundation/NSStream.h: New NSStream, NSInputStream and
NSOutputStream classes and constants.
* Headers/Foundation/Foundation.h: include NSStream.h
* Source/GSStream.m: System independent parts of NSStream
* Source/unix/NSStream.m: Unix specific class implementations
* Source/unix/GNUmakefile: Build NSStream.m
* Source/win32/NSStreamWin32.m: Win32 placeholders
* Source/win32/GNUmakefile: Build NSStreamWin32.m
* Source/GNUmakefile: Build GSStream.m
* Source/DocMakefile: Build NSStream documentation
Partial implementation of NSStream ... missing SSL, SOCKS, and
Win32 (apart from memory streams).

2006-02-15 Andrew Ruder <aeruder@ksu.edu>
* Headers/Foundation/NSString.h: Fixing the oldest bug in GNUstep?
The header has says NSObject since Andrew McCallum added the file
Expand Down
1 change: 1 addition & 0 deletions Headers/Foundation/Foundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include <Foundation/NSSerialization.h>
#include <Foundation/NSSet.h>
#include <Foundation/NSSortDescriptor.h>
#include <Foundation/NSStream.h>
#include <Foundation/NSString.h>
#include <Foundation/NSTask.h>
#include <Foundation/NSThread.h>
Expand Down
266 changes: 266 additions & 0 deletions Headers/Foundation/NSStream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
/** Interface for NSStream for GNUStep
Copyright (C) 2006 Free Software Foundation, Inc.
Written by: Derek Zhou <derekzhou@gmail.com>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/

#ifndef __NSStream_h_GNUSTEP_BASE_INCLUDE
#define __NSStream_h_GNUSTEP_BASE_INCLUDE

#include <Foundation/NSObject.h>

#if OS_API_VERSION(100400,GS_API_LATEST) && GS_API_VERSION(010200,GS_API_LATEST)

typedef enum {
NSStreamStatusNotOpen = 0,
NSStreamStatusOpening = 1,
NSStreamStatusOpen = 2,
NSStreamStatusReading = 3,
NSStreamStatusWriting = 4,
NSStreamStatusAtEnd = 5,
NSStreamStatusClosed = 6,
NSStreamStatusError = 7
} NSStreamStatus;

typedef enum {
NSStreamEventNone = 0,
NSStreamEventOpenCompleted = 1,
NSStreamEventHasBytesAvailable = 2,
NSStreamEventHasSpaceAvailable = 4,
NSStreamEventErrorOccurred = 8,
NSStreamEventEndEncountered = 16
} NSStreamEvent;

@class NSError;
@class NSHost;
@class NSInputStream;
@class NSOutputStream;
@class NSString;

/**
* NSStream is an abstract class for objects representing streams.
*/
@interface NSStream : NSObject

/**
* Creates and returns by reference an NSInputStream object and NSOutputStream
* object for a socket connection with the specified port on host.
*/
+ (void) getStreamsToHost: (NSHost *)host
port: (int)port
inputStream: (NSInputStream **)inputStream
outputStream: (NSOutputStream **)outputStream;

/**
* Closes the receiver.
*/
- (void) close;

/**
* Returns the receiver's delegate.
*/
- (id) delegate;

/**
* Opens the receiving stream.
*/
- (void) open;

/**
* Returns the receiver's property for the specified key.
*/
- (id) propertyForKey: (NSString *)key;

/**
* Removes the receiver from the NSRunLoop specified by aRunLoop
* running in the mode.
*/
- (void) removeFromRunLoop: (NSRunLoop *)aRunLoop forMode: (NSString *)mode;

/**
* Schedules the receiver on aRunLoop using the specified mode.
*/
- (void) scheduleInRunLoop: (NSRunLoop *)aRunLoop forMode: (NSString *)mode;

/**
* Sets the receiver's delegate.
*/
- (void) setDelegate: (id)delegate;

/**
* Sets the value of the property specified by key to property, returns YES
* if the key-value pair are accepted by the receiver.
*/
- (BOOL) setProperty: (id)property forKey: (NSString *)key;

/**
* Returns an NSError object representing the stream error, or nil if no error
* has been encountered.
*/
- (NSError *) streamError;

/**
* Returns the receiver's status.
*/
- (NSStreamStatus) streamStatus;

@end

@class NSData;

/**
* NSInputStream is a subclass of NSStream that provides read-only
* stream functionality.
*/
@interface NSInputStream : NSStream

/**
* Creates and returns an initialized NSInputStream object
* for reading from data.
*/
+ (id) inputStreamWithData: (NSData *)data;

/**
* Creates and returns an initialized NSInputStream object that reads data from
* the file at the specified path.
*/
+ (id) inputStreamWithFileAtPath: (NSString *)path;

/**
* Returns a pointer to the read buffer in buffer and, by reference, the number
* of bytes available in len.
*/
- (BOOL) getBuffer: (uint8_t **)buffer length: (unsigned int *)len;

/**
* Returns YES if the receiver has bytes available to read.
* The receiver may also return YES if a read must be attempted
* in order to determine the availability of bytes.
*/
- (BOOL) hasBytesAvailable;

/**
* Returns an initialized NSInputStream object for reading from data.
*/
- (id) initWithData: (NSData *)data;

/**
* Returns an initialized NSInputStream object for reading from the file at the
* specified path.
*/
- (id) initWithFileAtPath: (NSString *)path;

/**
* Reads up to len bytes into buffer, returning the actual number of bytes read.
*/
- (int) read: (uint8_t *)buffer maxLength: (unsigned int)len;

@end

/**
* NSOutputStream is a subclass of NSStream that provides
* write-only stream functionality.
*/
@interface NSOutputStream : NSStream

/**
* Creates and returns an initialized NSOutputStream object
* that can write to buffer, up to a maximum of capacity bytes.
*/
+ (id) outputStreamToBuffer: (uint8_t *)buffer capacity: (unsigned int)capacity;

/**
* Creates and returns an initialized NSOutputStream object
* for writing to the file specified by path.
*/
+ (id) outputStreamToFileAtPath: (NSString *)path append: (BOOL)shouldAppend;

/**
* Creates and returns an initialized NSOutputStream object
* that will write stream data to memory.
*/
+ (id) outputStreamToMemory;

/**
* Returns YES if the receiver can be written to,
* or if a write must be attempted
* in order to determine if space is available.
*/
- (BOOL) hasSpaceAvailable;

/**
* Returns an initialized NSOutputStream object that can write to buffer,
* up to a maximum of capacity bytes.
*/
- (id) initToBuffer: (uint8_t *)buffer capacity: (unsigned int)capacity;

/**
* Returns an initialized NSOutputStream object for writing to the file
* specified by path.<br />
* If shouldAppend is YES, newly written data will be appended to any
* existing file contents.
*/
- (id) initToFileAtPath: (NSString *)path append: (BOOL)shouldAppend;

/**
* Returns an initialized NSOutputStream object that will write to memory.
*/
- (id) initToMemory;

/**
* Writes the contents of buffer, up to a maximum of len bytes,
* to the receiver.
*/
- (int) write: (const uint8_t *)buffer maxLength: (unsigned int)len;

@end

@protocol GSStreamListener
/**
* The delegate receives this message when streamEvent
* has occurred on theStream.
*/
- (void) stream: (NSStream *)theStream handleEvent: (NSStreamEvent)streamEvent;
@end

GS_EXPORT NSString * const NSStreamDataWrittenToMemoryStreamKey;
GS_EXPORT NSString * const NSStreamFileCurrentOffsetKey;

GS_EXPORT NSString * const NSStreamSocketSecurityLevelKey;
GS_EXPORT NSString * const NSStreamSocketSecurityLevelNone;
GS_EXPORT NSString * const NSStreamSocketSecurityLevelSSLv2;
GS_EXPORT NSString * const NSStreamSocketSecurityLevelSSLv3;
GS_EXPORT NSString * const NSStreamSocketSecurityLevelTLSv1;
GS_EXPORT NSString * const NSStreamSocketSecurityLevelNegotiatedSSL;
GS_EXPORT NSString * const NSStreamSocketSSLErrorDomain;
GS_EXPORT NSString * const NSStreamSOCKSErrorDomain;
GS_EXPORT NSString * const NSStreamSOCKSProxyConfigurationKey;
GS_EXPORT NSString * const NSStreamSOCKSProxyHostKey;
GS_EXPORT NSString * const NSStreamSOCKSProxyPasswordKey;
GS_EXPORT NSString * const NSStreamSOCKSProxyPortKey;
GS_EXPORT NSString * const NSStreamSOCKSProxyUserKey;
GS_EXPORT NSString * const NSStreamSOCKSProxyVersion4;
GS_EXPORT NSString * const NSStreamSOCKSProxyVersion5;
GS_EXPORT NSString * const NSStreamSOCKSProxyVersionKey;


#endif

#endif /* __NSStream_h_GNUSTEP_BASE_INCLUDE */
1 change: 1 addition & 0 deletions Source/DocMakefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ NSRunLoop.h \
NSScanner.h \
NSSerialization.h \
NSSet.h \
NSStream.h \
NSString.h \
NSTask.h \
NSThread.h \
Expand Down
2 changes: 2 additions & 0 deletions Source/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ GSFormat.m \
GSFTPURLHandle.m \
GSHTTPURLHandle.m \
GSSet.m \
GSStream.m \
GSString.m \
GSValue.m \
NSAttributedString.m \
Expand Down Expand Up @@ -321,6 +322,7 @@ NSScanner.h \
NSSerialization.h \
NSSet.h \
NSSortDescriptor.h \
NSStream.h \
NSString.h \
NSTask.h \
NSThread.h \
Expand Down
Loading

0 comments on commit 5f07403

Please sign in to comment.