#include #include #include #include "MyConnection.h" @interface NSConnection (PrivateHack) - (void) handlePortMessage: (NSPortMessage*)msg; @end @interface NSPort (Hack) - (NSHost*) host; - (gsu16) portNumber; @end @implementation MyConnection static MyConnection *_currentConnection; + (MyConnection *) currentConnection { return _currentConnection; } - (void) handlePortMessage: (NSPortMessage*)msg { _currentConnection = (MyConnection *) [MyConnection connectionWithReceivePort: [msg receivePort] sendPort: [msg sendPort]]; [super handlePortMessage: msg]; _currentConnection = nil; } - (void) debug { NSPort *receivePort = [self receivePort]; NSPort *sendPort = [self sendPort]; printf ("%15s:%5d receive port, %15s:%5d send port\n", [[(NSHost *)[receivePort host] address] cString], [receivePort portNumber], [[(NSHost *)[sendPort host] address]cString], [sendPort portNumber]); } + (void) debug { int i; printf ("cur: "); if ([MyConnection currentConnection]) [[MyConnection currentConnection] debug]; else putchar ('\n'); printf ("def: "); if ([MyConnection defaultConnection]) [(MyConnection *)[MyConnection defaultConnection] debug]; else putchar ('\n'); NSArray *allConnections = [NSConnection allConnections]; for (i = 0; i < [allConnections count]; i++) { printf ("%3d: ", i); [(MyConnection *)[allConnections objectAtIndex: i] debug]; } } @end