I am creating a server which must run as a privileged helper tool on OS X. In it, I am attempting to use NSSocketPort
, NSFileHandle
, and NSNotificationCenter
to perform asynchronous IO on a listening socket. However, NSNotificationCenter
refuses to call the notification handler. Here is the relevant code:
NSSocketPort* sock = [[NSSocketPort alloc] initWithTCPPort:8080];
NSFileHandle* listener = [[NSFileHandle alloc] initWithFileDescriptor:sock.socket closeOnDealloc:NO]
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(onConnection:) name:NSFileHandleConnectionAcceptedNotification object:nil]
My main thread is running [NSRunLoop.mainRunLoop run]
, so that is not the issue. I have tried setting 'object' to 'listener' in the addObserver:
call, but that made no difference.