views:

174

answers:

1

I'm attempting to synchronously read from a CFReadStream objected created by CFStreamCreatePairWithSocketToHost. The stream opened fine but when I attempt to invoke CFReadStreamRead 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.

+1  A: 

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 */
tc.