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:
rfm 2006-08-08 16:23:46 +00:00
parent 09394ba7d8
commit 53020cec58
3 changed files with 47 additions and 8 deletions

View file

@ -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 <GSStreamListener>)_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 <GSStreamListener>)_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

View file

@ -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

View file

@ -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