Easy timeout for a CFWriteStreamWrite/CFReadStreamWriter?
Working on CFStreamCreatePairWithSocketToHost is always convenient:
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault,
(CFStringRef) hostnameOrIp,
aPort,
&readStream,
&writeStream);
as it gets you the goods (a r and w pipe) right away. Unfortunately CFReadStreamRead and CFWriteStreamRead block. Is there a clean way to set timeout on this (e.g. with a streamOption)开发者_如何学Go ? They are running in a thread - and as there are quite a few going on in parallel - would like to avoid runloop/signals - as any other pending read/writes should not be interrupted).
Thanks,
Dw.
You can use CFReadStreamHasBytesAvailable to check if something is available. If yes, CFReadStreamRead will not block. Or you can set client (CFReadStreamSetClient) and listen for notifications (kCFStreamEventHasBytesAvailable in your case).
加载中,请稍侯......
精彩评论