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
This commit is contained in:
Richard Frith-MacDonald 2006-08-08 16:23:46 +00:00
parent 3e6649d47d
commit 2006facfbc
3 changed files with 47 additions and 8 deletions

View file

@ -355,7 +355,8 @@ static RunLoopEventType typeForStream(NSStream *aStream)
- (void) _sendEvent: (NSStreamEvent)event - (void) _sendEvent: (NSStreamEvent)event
{ {
BOOL mayReachEnd = NO; NSStreamStatus last = [self streamStatus];
NSStreamStatus current;
if (event == NSStreamEventHasSpaceAvailable if (event == NSStreamEventHasSpaceAvailable
|| event == NSStreamEventHasBytesAvailable) || event == NSStreamEventHasBytesAvailable)
@ -366,17 +367,20 @@ static RunLoopEventType typeForStream(NSStream *aStream)
*/ */
_unhandledData = YES; _unhandledData = YES;
_unhandledData = YES; _unhandledData = YES;
mayReachEnd = YES;
} }
if (_delegateValid == YES) if (_delegateValid == YES)
{ {
[(id <GSStreamListener>)_delegate stream: self handleEvent: event]; [(id <GSStreamListener>)_delegate stream: self handleEvent: event];
}
/* If we were not at the end, but a read or write within the while ((current = [self streamStatus]) != last)
* delegate's handler method caused us to reach the end, we must {
* send an event to say so. 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) if (_delegateValid == YES)
{ {
@ -385,6 +389,19 @@ static RunLoopEventType typeForStream(NSStream *aStream)
handleEvent: event]; handleEvent: event];
} }
} }
else if (current == NSStreamStatusError)
{
if (_delegateValid == YES)
{
event = NSStreamEventErrorOccurred;
[(id <GSStreamListener>)_delegate stream: self
handleEvent: event];
}
}
else
{
return; // not an event.
}
} }
} }
@ -551,7 +568,6 @@ static RunLoopEventType typeForStream(NSStream *aStream)
[self _setStatus: myStatus]; [self _setStatus: myStatus];
[self _sendEvent: myEvent]; [self _sendEvent: myEvent];
// FIXME should we remain in run loop if NSStreamStatusAtEnd?
} }
@end @end
@ -632,7 +648,6 @@ static RunLoopEventType typeForStream(NSStream *aStream)
NSStreamEventEndEncountered; NSStreamEventEndEncountered;
[self _sendEvent: myEvent]; [self _sendEvent: myEvent];
// FIXME should we remain in run loop if NSStreamEventEndEncountered?
} }
@end @end

View file

@ -354,6 +354,17 @@ static void setNonblocking(int fd)
[super close]; [super close];
} }
- (void) _dispatch
{
if ([self streamStatus] == NSStreamStatusOpen)
{
[self _sendEvent: NSStreamEventHasBytesAvailable];
}
else
{
NSLog(@"_dispatch with unexpected status %d", [self streamStatus]);
}
}
@end @end
@implementation GSSocketInputStream @implementation GSSocketInputStream
@ -720,6 +731,17 @@ static void setNonblocking(int fd)
return [super propertyForKey: key]; return [super propertyForKey: key];
} }
- (void) _dispatch
{
if ([self streamStatus] == NSStreamStatusOpen)
{
[self _sendEvent: NSStreamEventHasSpaceAvailable];
}
else
{
NSLog(@"_dispatch with unexpected status %d", [self streamStatus]);
}
}
@end @end
@implementation GSSocketOutputStream @implementation GSSocketOutputStream
@ -1364,6 +1386,7 @@ static void setNonblocking(int fd)
socklen_t len = [ins sockLen]; socklen_t len = [ins sockLen];
int acceptReturn = accept((intptr_t)_loopID, [ins peerAddr], &len); int acceptReturn = accept((intptr_t)_loopID, [ins peerAddr], &len);
_unhandledData = NO;
if (acceptReturn < 0) if (acceptReturn < 0)
{ // test for real error { // test for real error
if (errno != EWOULDBLOCK if (errno != EWOULDBLOCK

View file

@ -1830,6 +1830,7 @@ else NSLog(@"EVENTS:%x", events.lNetworkEvents);
socklen_t len = [ins sockLen]; socklen_t len = [ins sockLen];
int acceptReturn = accept(_sock, [ins peerAddr], &len); int acceptReturn = accept(_sock, [ins peerAddr], &len);
_unhandledData = NO;
if (acceptReturn == INVALID_SOCKET) if (acceptReturn == INVALID_SOCKET)
{ {
errno = WSAGetLastError();// test for real error errno = WSAGetLastError();// test for real error