Skip to content

Commit

Permalink
Added debug
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Feb 12, 2024
1 parent c0b9ba8 commit e6e95d8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 23 deletions.
47 changes: 33 additions & 14 deletions Source/GSSocketStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2009,6 +2010,7 @@ + (void) initialize

- (void) open
{
NSDebugMLLog(@"NSStream", @"%@", self);
// could be opened because of sibling
if ([self _isOpened])
return;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -2179,6 +2182,8 @@ - (void) close

- (NSInteger) read: (uint8_t *)buffer maxLength: (NSUInteger)len
{
NSInteger result;

if (buffer == 0)
{
[NSException raise: NSInvalidArgumentException
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -2704,6 +2714,8 @@ - (void) close

- (NSInteger) write: (const uint8_t *)buffer maxLength: (NSUInteger)len
{
NSInteger result;

if (len == 0)
{
/*
Expand All @@ -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
Expand Down Expand Up @@ -2957,6 +2974,7 @@ - (void) open
int listenReturn;
SOCKET s;

NSDebugMLLog(@"NSStream", @"%@", self);
if (_currentStatus != NSStreamStatusNotOpen)
{
NSDebugMLLog(@"NSStream",
Expand Down Expand Up @@ -3026,6 +3044,7 @@ - (void) open

- (void) close
{
NSDebugMLLog(@"NSStream", @"%@", self);
#if defined(_WIN32)
if (_loopID != WSA_INVALID_EVENT)
{
Expand Down
37 changes: 28 additions & 9 deletions Source/GSStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e6e95d8

Please sign in to comment.