微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – AFNetworking / NSURLConnection接收NSPOSIXErrorDomain代码= 9“操作无法完成.坏文件描述符“

在我的应用程序中,使用AFNetworking / NSURLConnection发送请求到服务器我有时(很少)看到操作失败块中的这个错误
Error Domain=NSPOSIXErrorDomain Code=9 "The operation Couldn’t be completed. Bad file descriptor"

https://devforums.apple.com/message/278770#278770一个类似的问题的答案:

It means that someone has been deallocating file descriptors out from underneath NSURLConnection.

但是在我自己的代码中,我不会以任何方式触摸文件描述符的任何流.这只是简单的GET / POST请求.

可能是这个问题的原因?

有人在他们的AFNetworking操作中遇到这个错误吗?

此外,如果我真的想要,如何故意关闭这个文件描述符?这个问题的答案可以帮助我更好地了解问题.

解决方法

根据 this Apple TechNote多任务和网络,如果应用程序被挂起并且套接字被回收,您可以获得EBADF(POSIX错误9).

Note: When your app resumes execution the actual error returned by a
socket’s whose resources have been reclaimed is purposely not
specified here to allow for future refinements. However,in many cases
the error will be EBADF,which is probably not what you were
expecting! Under normal circumstances EBADF means that the app has passed an invalid file descriptor to a system call. However,in the case of a socket whose resources have been reclaimed,it does not mean that the file descriptor was invalid,just that the socket is no longer usable.

原文地址:https://www.jb51.cc/iOS/329887.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐