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 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...