Starting with OS X 10.7 and iOS 5.0, NSFileHandle has two new properties: readabilityHandler and writeabilityHandler. I tried to use writeabilityHandler but no luck. The documentation looks weird, it looks like they copied the readabilityHandler description and replaced the word with a record .
According to the documentation that assigns the block, it should eventually call the block. Is not.
- (void)sendResponse:(NSData*)dataToSend { _incomingHandle.writeabilityHandler = ^(NSFileHandle* fileHandle) { [fileHandle writeData:dataToSend]; // exception is thrown here fileHandle.writeabilityHandler = nil; }; // Above block is not called without this line: //[_incomingHandle writeData:dataToSend]; }
It is called only if I try to write to the descriptor synchronously [_incomingHandle writeData:dataToSend] , which makes no sense. After it is called, it throws an exception: EXC_BAD_INSTRUCTION
*** Terminating app due to uncaught exception 'NSFileHandleOperationException', reason: '*** -[NSConcreteFileHandle writeData:]: Resource temporarily unavailable'
I also tried to send data in parts. Bad luck.
Has anyone successfully used this property?
source share