From 00cec8039197eafd15667cb991e31f95f4e7c8eb Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Sat, 18 Jun 2016 06:42:12 +0000 Subject: [PATCH] Unchedule I/O events when entering an error state git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39875 72102866-910b-0410-8b05-ffd578937521 --- Source/GSStream.h | 2 +- Source/GSStream.m | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Source/GSStream.h b/Source/GSStream.h index d87c4fe51..4f270dd22 100644 --- a/Source/GSStream.h +++ b/Source/GSStream.h @@ -75,7 +75,7 @@ { \ id _delegate; /* Delegate controls operation. */\ NSMutableDictionary *_properties; /* storage for properties */\ - BOOL _delegateValid;/* whether the delegate responds*/\ + BOOL _delegateValid; /* whether the delegate responds*/\ NSError *_lastError; /* last error occured */\ NSStreamStatus _currentStatus;/* current status */\ NSMapTable *_loops; /* Run loops and their modes. */\ diff --git a/Source/GSStream.m b/Source/GSStream.m index 5e2f5b394..bce1954ca 100644 --- a/Source/GSStream.m +++ b/Source/GSStream.m @@ -407,7 +407,7 @@ static RunLoopEventType typeForStream(NSStream *aStream) { NSDebugMLLog(@"NSStream", @"record error: %@ - %@", self, anError); ASSIGN(_lastError, anError); - _currentStatus = NSStreamStatusError; + [self _setStatus: NSStreamStatusError]; } - (void) _resetEvents: (NSUInteger)mask @@ -533,7 +533,22 @@ static RunLoopEventType typeForStream(NSStream *aStream) - (void) _setStatus: (NSStreamStatus)newStatus { - _currentStatus = newStatus; + if (_currentStatus != newStatus) + { + if (NSStreamStatusError == newStatus && NSCountMapTable(_loops) > 0) + { + /* After an error, we are in the run loops only to trigger + * errors, not for I/O, sop we must re-schedule in the right mode. + */ + [self _unschedule]; + _currentStatus = newStatus; + [self _schedule]; + } + else + { + _currentStatus = newStatus; + } + } } - (BOOL) _unhandledData