我正在创建一个服务器,它必须在 OS X 上作为特权帮助工具运行。在其中,我尝试使用NSSocketPort
, NSFileHandle
, 并NSNotificationCenter
在侦听套接字上执行异步 IO。但是,NSNotificationCenter
拒绝调用通知处理程序。以下是相关代码:
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]
我的主线程正在运行[NSRunLoop.mainRunLoop run]
,所以这不是问题。我曾尝试在通话中将 'object' 设置为 'listener' addObserver:
,但这并没有什么区别。