After creating a socket with CFStreamCreatePairWithSocketToHost is there a way to retrieve the socket file descriptor of the underlying socket?
The reason I ask is that if I create a socket with
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)host, port,
&readStream, &writeStream);
the socket works fine, I can read from it and write to it, but I can't retrieve the socket file descriptor.
However, if I create it using CFSocketCreate:
socket = CFSocketCreate(kCFAllocatorDefault, AF_INET, SOCK_STREAM,
IPPROTO_TCP, 0, NULL, NULL);
int fd = CFSocketGetNative(socket);
struct sockaddr_in addr;
memset(&sin, 0, sizeof(addr));
addr.sin_len = sizeof(addr);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
CFDataRef address = CFDataCreate(NULL,(unsigned char*)&sin,sizeof(sin));
CFSocketConnectToAddress(socket, address, 1);
CFStreamCreatePairWithSocket(kCFAllocatorDefault, CFSocketGetNative(socket),
&readStream, &writeStream);
I can get the file descriptor of the socket, however when I try to read from it blocks.