使用CFWriteStream的异步IO [英] Asynchronous IO with CFWriteStream

查看:343
本文介绍了使用CFWriteStream的异步IO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CFWriteStreamScheduleWithRunLoop和CFWriteStreamWrite来做异步IO。这里的问题:似乎只有一个CFWriteStreamWrite调用是安全的(无阻塞)每个kCFStreamEventCanAcceptBytes通知,因为从第二次调用,我们不能保证套接字准备好接受更多的数据。所以如果我们想要调用CFWriteStreamWrite调用,我们必须重复等待kCFStreamEventCanAcceptBytes和调用CFWriteStreamWriten次。

I'm using CFWriteStreamScheduleWithRunLoop and CFWriteStreamWrite to do asynchronous IO. Here's the question: it seems that only one CFWriteStreamWrite call is safe (free of blocking) per each kCFStreamEventCanAcceptBytes notification, because from the second call, we can't guarantee that the socket is ready to accept more data. So if we want to make n CFWriteStreamWrite calls, we'll have to repeat "waiting for kCFStreamEventCanAcceptBytes" and "calling CFWriteStreamWrite" n times.

这是正确的吗? >
感谢!

Is this correct?
Thanks!

推荐答案

与其他问题相同的答案:call CFWriteStreamCanAcceptBytes ,以查看是否仍可安全写入。

Same answer as in the other question: call CFWriteStreamCanAcceptBytes() on the stream to see if it's still safe to write on it.

这篇关于使用CFWriteStream的异步IO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆