Added some debug logging

This commit is contained in:
Richard Frith-Macdonald 2021-05-19 11:15:29 +01:00
parent 8d75688048
commit 391c00b058

View file

@ -140,22 +140,24 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
*/
- (NSInteger) write: (const void*)buf length: (NSUInteger)len
{
int result;
#if USE_ZLIB
if (gzDescriptor != 0)
{
len = gzwrite(gzDescriptor, (char*)buf, len);
result = gzwrite(gzDescriptor, (char*)buf, len);
}
else
#endif
if (isSocket)
{
len = send((SOCKET)_get_osfhandle(descriptor), buf, len, 0);
result = send((SOCKET)_get_osfhandle(descriptor), buf, len, 0);
}
else
{
len = write(descriptor, buf, len);
result = write(descriptor, buf, len);
}
return len;
return result;
}
static BOOL
@ -678,8 +680,8 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
{
NSNotificationCenter *q;
q = [NSNotificationCenter defaultCenter];
[q postNotification: n];
q = [NSNotificationCenter defaultCenter];
[q postNotification: n];
}
}
@ -1736,15 +1738,14 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
RELEASE(info);
/* On mswindows we receive a write trigger only when a write actually
* completes, so if there is no write in progress, we trigger one.
* Watching the descriptor too ensures that if a write can't complete
* immediately, we will try to complete it when space becomes available.
*/
if (writeWasInProgress == NO)
[self watchWriteDescriptor];
if (NO == writeWasInProgress)
{
[self receivedEventWrite];
}
else
{
[self watchWriteDescriptor];
}
}
- (void) writeInBackgroundAndNotify: (NSData*)item;
@ -1840,11 +1841,15 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
{
e = (void*)(uintptr_t)descriptor;
t = ET_TRIGGER;
NSDebugMLLog(@"NSFileHandle", @"Ignore read trigger for %p in %@",
self, modes);
}
else
{
e = (void*)(uintptr_t)event;
t = ET_HANDLE;
NSDebugMLLog(@"NSFileHandle", @"Ignore read handle for %p in %@",
self, modes);
}
if (modes && [modes count])
@ -1893,11 +1898,15 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
{
e = (void*)(uintptr_t)descriptor;
t = ET_TRIGGER;
NSDebugMLLog(@"NSFileHandle", @"Ignore write trigger for %p in %@",
self, modes);
}
else
{
e = (void*)(uintptr_t)event;
t = ET_HANDLE;
NSDebugMLLog(@"NSFileHandle", @"Ignore write trigger for %p in %@",
self, modes);
}
if (modes && [modes count])
@ -1939,11 +1948,15 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
{
e = (void*)(uintptr_t)descriptor;
t = ET_TRIGGER;
NSDebugMLLog(@"NSFileHandle", @"Watch read trigger for %p in %@",
self, modes);
}
else
{
e = (void*)(uintptr_t)event;
t = ET_HANDLE;
NSDebugMLLog(@"NSFileHandle", @"Watch read handle for %p in %@",
self, modes);
}
if (modes && [modes count])
@ -1990,11 +2003,15 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
{
e = (void*)(uintptr_t)descriptor;
t = ET_TRIGGER;
NSDebugMLLog(@"NSFileHandle", @"Watch write trigger for %p in %@",
self, modes);
}
else
{
e = (void*)(uintptr_t)event;
t = ET_HANDLE;
NSDebugMLLog(@"NSFileHandle", @"Watch write handle for %p in %@",
self, modes);
}
if (modes && [modes count])
@ -2019,6 +2036,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
}
else
{
NSDebugMLLog(@"NSFileHandle", @"Watch write no data for %p", self);
}
}
@ -2209,13 +2227,16 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
writeOK = YES;
}
connectOK = NO;
NSDebugMLLog(@"NSFileHandle", @"Connection complete for %p: status: %d",
self, connectOK);
[self postWriteNotification];
}
else
{
NSData *item;
NSData *item;
int length;
const void *ptr;
BOOL failed = NO;
item = [info objectForKey: NSFileHandleNotificationDataItem];
length = [item length];
@ -2223,9 +2244,11 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
while (writePos < length)
{
int written;
int offset = writePos;
int amount = length - offset;
written = [self write: (char*)ptr+writePos
length: length-writePos];
written = [self write: ((char*)ptr) + offset
length: amount];
if (written <= 0)
{
if (WSAGetLastError()!= WSAEINTR
@ -2236,16 +2259,21 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
s = [NSString stringWithFormat:
@"Write attempt failed - %@", [NSError _last]];
[info setObject: s forKey: GSFileHandleNotificationError];
[self postWriteNotification];
failed = YES;
}
break;
}
else
{
writePos += written;
}
if (written <= 0)
{
break;
}
}
if (writePos >= length)
NSDebugMLLog(@"NSFileHandle", @"Wrote up to %d bytes of %d for %p",
writePos, length, self);
if (YES == failed || writePos >= length)
{ // Write operation completed.
[self postWriteNotification];
}