discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSStream and getting space available


From: Thomas Davie
Subject: NSStream and getting space available
Date: Fri, 15 Jun 2012 10:19:29 +0100

Hi all,

I'm currently trying to debug some stream code that works on OS X, but appears 
to be not quite right to satisfy GNUstep.

The code to connect is listed below, the method calling connect subsequently 
runs the runloop repeatedly.  As you can see, I have moved scheduleInRunLoop 
below opening the streams, as it appears that in GNUstep addStream:inModes: is 
only called when opening the stream, and only if the stream is not already in a 
run loop (i.e. the stream is not properly added if you schedule it before 
opening it).

This got me as far as receiving an NSStreamEventOpenCompleted in my stream 
delegate.  Unfortunately, what I don't receive is an 
NSStreamEventHasSpaceAvailable, and I don't see why.  Is this the expected 
behaviour on GNUstep, or is something further going wrong?

Thanks

Tom Davie

> - (void)connect
> {
>     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
> 
> #if __APPLE__
>     CFReadStreamRef  readStream;
>     CFWriteStreamRef writeStream;
>     CFStreamCreatePairWithSocketToHost(NULL,
>                                        (CFStringRef)[self server],
>                                        (UInt32)[self port],
>                                        &readStream,
>                                        &writeStream);
>     [self setInputStream:(NSInputStream *)readStream];
>     [self setOutputStream:(NSOutputStream *)writeStream];
>     CFRelease(readStream);
>     CFRelease(writeStream);
> #else
>     NSInputStream *readStream;
>     NSOutputStream *writeStream;
>     [NSStream getStreamsToHost:[NSHost hostWithAddress:[self server]]
>                           port:[self port]
>                    inputStream:&readStream
>                   outputStream:&writeStream];
>     [self setInputStream:(NSInputStream *)readStream];
>     [self setOutputStream:(NSOutputStream *)writeStream];
>     [readStream release];
>     [writeStream release];
> #endif
> 
>     [[self inputStream] setDelegate:self];
>     [[self outputStream] setDelegate:self];
>     NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
>    // [[self inputStream] scheduleInRunLoop:runLoop 
> forMode:NSDefaultRunLoopMode];
>    //  [[self outputStream] scheduleInRunLoop:runLoop 
> forMode:NSDefaultRunLoopMode];
>     [[self inputStream] open];
>     [[self outputStream] open];
> 
>     [[self inputStream] scheduleInRunLoop:runLoop 
> forMode:NSDefaultRunLoopMode];
>     [[self outputStream] scheduleInRunLoop:runLoop 
> forMode:NSDefaultRunLoopMode];
> 
>     [pool release];
> }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]