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

前端之家收集整理的这篇文章主要介绍了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.

猜你在找的iOS相关文章