iPhone OS 4.0.x - 在后台阻止 I/O 操作
我目前正在实现一些在后台模式下从 TCP 套接字读取的逻辑。
CFReadStreamRead 函数用于从套接字获取一些数据,目前一切正常。
但我想知道 iPhone OS 4.x 如何处理后台模式下的阻塞 I/O 操作。例如:CFReadStreamRead
函数在等待某些传入数据时可能会阻塞数小时。
后台任务有10分钟之类的官方限制吗?如果长时间运行阻塞 I/O 操作,我的应用程序会被 iPhone OS 杀死吗?
请注意 - 我没有在后台任务中运行阻塞 I/O 函数。代码本身位于我的UIApplicationDelegate
的applicationDidEnterBackground
方法中。
应用程序本身在 Info.plst 文件中使用“voip”参数进行配置 + CFReadStream 根据 Apple 的建议使用 kCFStreamNetworkServiceTypeVoIP
参数进行配置。
所以基本上这是 VoIP 应用在后台模式下的常规场景。
谢谢!
I'm currently implementing some logic for reading from TCP socket in the background mode.
CFReadStreamRead
function is being used to fetch some data from socket and for now everything works fine.
But I'm wondering how iPhone OS 4.x treats blocking I/O operations in the background mode. For example: CFReadStreamRead
function may block for hours while waiting for some incoming data.
Are there any official constraints like 10 minutes for the background tasks? Will my application be killed by iPhone OS for the case of long-running blocking I/O operation?
Please note - I'm not running the blocking I/O function in the background task. Code itself is situated inapplicationDidEnterBackground
method of myUIApplicationDelegate
.
Application itself is configured with "voip" parameter in Info.plst file + CFReadStream is configured according to the recommendations of Apple withkCFStreamNetworkServiceTypeVoIP
parameter.
So basically this is a regular scenario of VoIP application in the background mode.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其替换为
sleep(86400)
,在调试器中附加到它,然后查看您被杀死之前还有多长时间。我认为不会那么长;您应该及时响应applicationDidEnterBackground:
。几乎可以肯定,它不会给您比beginBackgroundTaskWithExpirationHandler:
更多的时间。尝试检查
[UIApplication backgroundTimeRemaining]
。Replace it with
sleep(86400)
, attach to it in the debugger, and see how long it is before you're killed. I don't think it'll be that long; you're supposed to respond toapplicationDidEnterBackground:
in a timely fashion. It almost certainly won't give you more time thanbeginBackgroundTaskWithExpirationHandler:
.Try checking
[UIApplication backgroundTimeRemaining]
.