接收错误域= kCFErrorDomainCFNetwork当尝试从ReadStream读取时,代码= 2 [英] Receiving Error Domain=kCFErrorDomainCFNetwork Code=2 when attempting to read from ReadStream
问题描述
我正在尝试从 CFStreamCreatePairWithSocketToHost
创建的 CFReadStream
对象同步读取。流打开正常,但是当我尝试在循环中调用 CFReadStreamRead
时,CFReadStreamRead()返回-1,结果错误是:
错误域= kCFErrorDomainCFNetwork代码= 2无法完成操作(kCFErrorDomainCFNetwork错误2.)UserInfo = 0x14a920 {kCFGetAddrInfoFailureKey = 8}
我在使用这个ReadStream时也收到同样的错误 - 我收到的第一个回调是这个错误。
简短的故事:可能是DNS解析失败。
文档说流不打开连接到指定的主机,直到打开其中一个流,并为kCFGetAddrInfoFailureKey
查询此键返回最后一个返回的错误代码getaddrinfo(3)以响应DNS查找。要解释结果,请查找/usr/include/netdb.h中的错误代码。
netdb.h说
#define EAI_NONAME 8 / * hostname没有提供或不知道* /
pre>
I'm attempting to synchronously read from a
CFReadStream
objected created byCFStreamCreatePairWithSocketToHost
. The stream opened fine but when I attempt to invokeCFReadStreamRead
on it in a loop, CFReadStreamRead() returns -1 and the resulting error is:
Error Domain=kCFErrorDomainCFNetwork Code=2 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 2.)" UserInfo=0x14a920 {kCFGetAddrInfoFailureKey=8}
I'm also receiving this same exact error when using this ReadStream asynchronously- the first callback I receive is this error.
解决方案The short story: Probably a DNS resolution failure.
The docs say "The streams do not open a connection to the specified host until one of the streams is opened", and for kCFGetAddrInfoFailureKey,
Querying this key returns the last error code returned by getaddrinfo(3) in response to a DNS lookup. To interpret the results, look up the error code in /usr/include/netdb.h.
netdb.h says
#define EAI_NONAME 8 /* hostname nor servname provided, or not known */
这篇关于接收错误域= kCFErrorDomainCFNetwork当尝试从ReadStream读取时,代码= 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!