开发者

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜