From e6e95d81f6636794c473d61f0d37f898d48e545d Mon Sep 17 00:00:00 2001 From: rfm Date: Mon, 12 Feb 2024 17:39:22 +0000 Subject: [PATCH] Added debug --- Source/GSSocketStream.m | 47 +++++++++++++++++++++++++++++------------ Source/GSStream.m | 37 ++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/Source/GSSocketStream.m b/Source/GSSocketStream.m index 703aa25dcf..fd95bbc3d7 100644 --- a/Source/GSSocketStream.m +++ b/Source/GSSocketStream.m @@ -1750,8 +1750,9 @@ - (void) dealloc - (NSString*) description { - return [NSString stringWithFormat: @"%@ sock %lld loopID %p", - [super description], (long long)_sock, _loopID]; + return [NSString stringWithFormat: @"<%s: %p sock %lld loopID %p mask %@>", + class_getName(object_getClass(self)), self, + (long long)_sock, _loopID, [self _stringFromEvents]]; } - (id) init @@ -2009,6 +2010,7 @@ + (void) initialize - (void) open { + NSDebugMLLog(@"NSStream", @"%@", self); // could be opened because of sibling if ([self _isOpened]) return; @@ -2117,6 +2119,7 @@ - (void) open - (void) close { + NSDebugMLLog(@"NSStream", @"%@", self); /* If the socket descriptor is still present, we need to close it to * avoid a leak no matter what the nominal state of the stream is. * The descriptor is created before the stream is formally opened. @@ -2179,6 +2182,8 @@ - (void) close - (NSInteger) read: (uint8_t *)buffer maxLength: (NSUInteger)len { + NSInteger result; + if (buffer == 0) { [NSException raise: NSInvalidArgumentException @@ -2191,9 +2196,12 @@ - (NSInteger) read: (uint8_t *)buffer maxLength: (NSUInteger)len } if (_handler == nil) - return [self _read: buffer maxLength: len]; + result = [self _read: buffer maxLength: len]; else - return [_handler read: buffer maxLength: len]; + result = [_handler read: buffer maxLength: len]; + NSDebugMLLog(@"NSStream", @"%@ tried %lld result %lld", + self, (long long)len, (long long) result); + return result; } - (NSInteger) _read: (uint8_t *)buffer maxLength: (NSUInteger)len @@ -2531,6 +2539,7 @@ - (NSInteger) _write: (const uint8_t *)buffer maxLength: (NSUInteger)len - (void) open { + NSDebugMLLog(@"NSStream", @"%@", self); // could be opened because of sibling if ([self _isOpened]) return; @@ -2641,6 +2650,7 @@ - (void) open - (void) close { + NSDebugMLLog(@"NSStream", @"%@", self); /* If the socket descriptor is still present, we need to close it to * avoid a leak no matter what the nominal state of the stream is. * The descriptor is created before the stream is formally opened. @@ -2704,6 +2714,8 @@ - (void) close - (NSInteger) write: (const uint8_t *)buffer maxLength: (NSUInteger)len { + NSInteger result; + if (len == 0) { /* @@ -2722,19 +2734,24 @@ - (NSInteger) write: (const uint8_t *)buffer maxLength: (NSUInteger)len * detect that no more data is arriving, and shut down. */ _events &= ~NSStreamEventHasSpaceAvailable; - return 0; + result = 0; } - - if (buffer == 0) + else { - [NSException raise: NSInvalidArgumentException - format: @"null pointer for buffer"]; - } + if (buffer == 0) + { + [NSException raise: NSInvalidArgumentException + format: @"null pointer for buffer"]; + } - if (_handler == nil) - return [self _write: buffer maxLength: len]; - else - return [_handler write: buffer maxLength: len]; + if (_handler == nil) + result = [self _write: buffer maxLength: len]; + else + result = [_handler write: buffer maxLength: len]; + } + NSDebugMLLog(@"NSStream", @"%@ tried %lld result %lld", + self, (long long)len, (long long) result); + return result; } - (void) _dispatch @@ -2957,6 +2974,7 @@ - (void) open int listenReturn; SOCKET s; + NSDebugMLLog(@"NSStream", @"%@", self); if (_currentStatus != NSStreamStatusNotOpen) { NSDebugMLLog(@"NSStream", @@ -3026,6 +3044,7 @@ - (void) open - (void) close { + NSDebugMLLog(@"NSStream", @"%@", self); #if defined(_WIN32) if (_loopID != WSA_INVALID_EVENT) { diff --git a/Source/GSStream.m b/Source/GSStream.m index a535f683f5..c24d4818d5 100644 --- a/Source/GSStream.m +++ b/Source/GSStream.m @@ -126,8 +126,7 @@ - (void) removeStream: (NSStream*)aStream mode: (NSString*)mode RunLoopEventType type = typeForStream(aStream); void *event = [aStream _loopID]; - NSDebugMLLog(@"NSStream", - @"-removeStream:mode: %@ (desc %d,%d) from %@ mode %@", + NSDebugMLLog(@"NSStream", @"%@ (desc %d,%d) from %@ mode %@", aStream, (int)(intptr_t)event, type, self, mode); /* We may have added the stream more than once (eg if the stream -open * method was called more than once, so we need to remove all event @@ -227,7 +226,7 @@ - (void) receivedEvent: (void*)data extra: (void*)extra forMode: (NSString*)mode { -// NSDebugMLLog(@"NSStream", @"receivedEvent for %@ - %d", self, type); + NSDebugMLLog(@"NSStream", @"receivedEvent for %@ - %d", self, type); [self _dispatch]; } @@ -341,17 +340,37 @@ - (NSStreamStatus) streamStatus - (NSString*) _stringFromEvents { NSMutableString *s = [NSMutableString stringWithCapacity: 100]; + BOOL bits = 0; + if (0 == _events) + { + return @"None"; + } if (_events & NSStreamEventOpenCompleted) - [s appendString: @"|NSStreamEventOpenCompleted"]; + { + if (bits++ > 0) [s appendString: @"|"]; + [s appendString: @"OpenCompleted"]; + } if (_events & NSStreamEventHasBytesAvailable) - [s appendString: @"|NSStreamEventHasBytesAvailable"]; + { + if (bits++ > 0) [s appendString: @"|"]; + [s appendString: @"HasBytesAvailable"]; + } if (_events & NSStreamEventHasSpaceAvailable) - [s appendString: @"|NSStreamEventHasSpaceAvailable"]; + { + if (bits++ > 0) [s appendString: @"|"]; + [s appendString: @"HasSpaceAvailable"]; + } if (_events & NSStreamEventErrorOccurred) - [s appendString: @"|NSStreamEventErrorOccurred"]; + { + if (bits++ > 0) [s appendString: @"|"]; + [s appendString: @"ErrorOccurred"]; + } if (_events & NSStreamEventEndEncountered) - [s appendString: @"|NSStreamEventEndEncountered"]; + { + if (bits++ > 0) [s appendString: @"|"]; + [s appendString: @"EndEncountered"]; + } return s; } @@ -546,7 +565,7 @@ - (void) _sendEvent: (NSStreamEvent)event - (void) _sendEvent: (NSStreamEvent)event delegate: (id)delegate { NSDebugMLLog(@"NSStream", - @"%@ sendEvent %@", self, [self stringFromEvent:event]); + @"%@ event:%@ delegate: %@", self, [self stringFromEvent: event], delegate); if (event == NSStreamEventNone) { return;