mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Added debug
This commit is contained in:
parent
c0b9ba8992
commit
e6e95d81f6
2 changed files with 62 additions and 24 deletions
|
@ -1750,8 +1750,9 @@ setNonBlocking(SOCKET fd)
|
|||
|
||||
- (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 @@ setNonBlocking(SOCKET fd)
|
|||
|
||||
- (void) open
|
||||
{
|
||||
NSDebugMLLog(@"NSStream", @"%@", self);
|
||||
// could be opened because of sibling
|
||||
if ([self _isOpened])
|
||||
return;
|
||||
|
@ -2117,6 +2119,7 @@ setNonBlocking(SOCKET fd)
|
|||
|
||||
- (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 @@ setNonBlocking(SOCKET fd)
|
|||
|
||||
- (NSInteger) read: (uint8_t *)buffer maxLength: (NSUInteger)len
|
||||
{
|
||||
NSInteger result;
|
||||
|
||||
if (buffer == 0)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
|
@ -2191,9 +2196,12 @@ setNonBlocking(SOCKET fd)
|
|||
}
|
||||
|
||||
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 @@ setNonBlocking(SOCKET fd)
|
|||
|
||||
- (void) open
|
||||
{
|
||||
NSDebugMLLog(@"NSStream", @"%@", self);
|
||||
// could be opened because of sibling
|
||||
if ([self _isOpened])
|
||||
return;
|
||||
|
@ -2641,6 +2650,7 @@ setNonBlocking(SOCKET fd)
|
|||
|
||||
- (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 @@ setNonBlocking(SOCKET fd)
|
|||
|
||||
- (NSInteger) write: (const uint8_t *)buffer maxLength: (NSUInteger)len
|
||||
{
|
||||
NSInteger result;
|
||||
|
||||
if (len == 0)
|
||||
{
|
||||
/*
|
||||
|
@ -2722,19 +2734,24 @@ setNonBlocking(SOCKET fd)
|
|||
* detect that no more data is arriving, and shut down.
|
||||
*/
|
||||
_events &= ~NSStreamEventHasSpaceAvailable;
|
||||
return 0;
|
||||
result = 0;
|
||||
}
|
||||
|
||||
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 (buffer == 0)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"null pointer for buffer"];
|
||||
}
|
||||
|
||||
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 @@ setNonBlocking(SOCKET fd)
|
|||
int listenReturn;
|
||||
SOCKET s;
|
||||
|
||||
NSDebugMLLog(@"NSStream", @"%@", self);
|
||||
if (_currentStatus != NSStreamStatusNotOpen)
|
||||
{
|
||||
NSDebugMLLog(@"NSStream",
|
||||
|
@ -3026,6 +3044,7 @@ setNonBlocking(SOCKET fd)
|
|||
|
||||
- (void) close
|
||||
{
|
||||
NSDebugMLLog(@"NSStream", @"%@", self);
|
||||
#if defined(_WIN32)
|
||||
if (_loopID != WSA_INVALID_EVENT)
|
||||
{
|
||||
|
|
|
@ -126,8 +126,7 @@ static RunLoopEventType typeForStream(NSStream *aStream)
|
|||
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 @@ static RunLoopEventType typeForStream(NSStream *aStream)
|
|||
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 @@ static RunLoopEventType typeForStream(NSStream *aStream)
|
|||
- (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 @@ static RunLoopEventType typeForStream(NSStream *aStream)
|
|||
- (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;
|
||||
|
|
Loading…
Reference in a new issue