开发者

Easy timeout for a CFWriteStreamWrite/CFReadStreamWriter?

开发者 https://www.devze.com 2023-02-04 22:54 出处:网络
Working on CFStreamCreatePairWithSocketToHost is always convenient: CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault,

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

精彩评论

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

关注公众号