From 2006facfbcfd4b550a636952327891c7aa85579f Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Tue, 8 Aug 2006 16:23:46 +0000 Subject: [PATCH] Fixup _unusedData flag for server streams doing an accept. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23217 72102866-910b-0410-8b05-ffd578937521 --- Source/GSStream.m | 31 +++++++++++++++++++++++-------- Source/unix/NSStream.m | 23 +++++++++++++++++++++++ Source/win32/NSStreamWin32.m | 1 + 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/Source/GSStream.m b/Source/GSStream.m index c5f98de91..94764e0f5 100644 --- a/Source/GSStream.m +++ b/Source/GSStream.m @@ -355,7 +355,8 @@ static RunLoopEventType typeForStream(NSStream *aStream) - (void) _sendEvent: (NSStreamEvent)event { - BOOL mayReachEnd = NO; + NSStreamStatus last = [self streamStatus]; + NSStreamStatus current; if (event == NSStreamEventHasSpaceAvailable || event == NSStreamEventHasBytesAvailable) @@ -366,17 +367,20 @@ static RunLoopEventType typeForStream(NSStream *aStream) */ _unhandledData = YES; _unhandledData = YES; - mayReachEnd = YES; } if (_delegateValid == YES) { [(id )_delegate stream: self handleEvent: event]; + } - /* If we were not at the end, but a read or write within the - * delegate's handler method caused us to reach the end, we must - * send an event to say so. + while ((current = [self streamStatus]) != last) + { + last = current; + + /* If we our status changed while the handler was dealing with an + * event, we must send it the new event to let it know. */ - if (mayReachEnd == YES && [self streamStatus] == NSStreamStatusAtEnd) + if (current == NSStreamStatusAtEnd) { if (_delegateValid == YES) { @@ -385,6 +389,19 @@ static RunLoopEventType typeForStream(NSStream *aStream) handleEvent: event]; } } + else if (current == NSStreamStatusError) + { + if (_delegateValid == YES) + { + event = NSStreamEventErrorOccurred; + [(id )_delegate stream: self + handleEvent: event]; + } + } + else + { + return; // not an event. + } } } @@ -551,7 +568,6 @@ static RunLoopEventType typeForStream(NSStream *aStream) [self _setStatus: myStatus]; [self _sendEvent: myEvent]; - // FIXME should we remain in run loop if NSStreamStatusAtEnd? } @end @@ -632,7 +648,6 @@ static RunLoopEventType typeForStream(NSStream *aStream) NSStreamEventEndEncountered; [self _sendEvent: myEvent]; - // FIXME should we remain in run loop if NSStreamEventEndEncountered? } @end diff --git a/Source/unix/NSStream.m b/Source/unix/NSStream.m index 0fb838200..bc33c1e19 100644 --- a/Source/unix/NSStream.m +++ b/Source/unix/NSStream.m @@ -354,6 +354,17 @@ static void setNonblocking(int fd) [super close]; } +- (void) _dispatch +{ + if ([self streamStatus] == NSStreamStatusOpen) + { + [self _sendEvent: NSStreamEventHasBytesAvailable]; + } + else + { + NSLog(@"_dispatch with unexpected status %d", [self streamStatus]); + } +} @end @implementation GSSocketInputStream @@ -720,6 +731,17 @@ static void setNonblocking(int fd) return [super propertyForKey: key]; } +- (void) _dispatch +{ + if ([self streamStatus] == NSStreamStatusOpen) + { + [self _sendEvent: NSStreamEventHasSpaceAvailable]; + } + else + { + NSLog(@"_dispatch with unexpected status %d", [self streamStatus]); + } +} @end @implementation GSSocketOutputStream @@ -1364,6 +1386,7 @@ static void setNonblocking(int fd) socklen_t len = [ins sockLen]; int acceptReturn = accept((intptr_t)_loopID, [ins peerAddr], &len); + _unhandledData = NO; if (acceptReturn < 0) { // test for real error if (errno != EWOULDBLOCK diff --git a/Source/win32/NSStreamWin32.m b/Source/win32/NSStreamWin32.m index 896828ce7..39f483c44 100644 --- a/Source/win32/NSStreamWin32.m +++ b/Source/win32/NSStreamWin32.m @@ -1830,6 +1830,7 @@ else NSLog(@"EVENTS:%x", events.lNetworkEvents); socklen_t len = [ins sockLen]; int acceptReturn = accept(_sock, [ins peerAddr], &len); + _unhandledData = NO; if (acceptReturn == INVALID_SOCKET) { errno = WSAGetLastError();// test for real error