Hi Everyone. First post to this group.
I'm controlling the output stream created by
::CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)hostAddress, portNum, &readStream, &writeStream); ::CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue); ::CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
and later bridged to NSInputStream and NSOutputStream instances, via its internal native socket, using the posix getsockopt and setsockopt calls.
The properties I need to work with are the read (input) and write (output) buffer sizes, and the write (output) socket's buffer pending content size.
Things like this... oss = getsockopt(socket,SOL_SOCKET,SO_RCVBUF,&value,&valueSize); oss = setsockopt(socket,SOL_SOCKET,SO_SNDBUF, &value, sizeof(value); oss = getsockopt(socket,SOL_SOCKET,SO_NWRITE, &value, &valueSize);
etc.
To retrieve the native socket I'm using code like this:
// Getting the amount of bytes in the output socket buffer which are waiting to be sent - (int) getSocketOutputBufferPendingSize:(uint32_t*)bufSize { int oss = -1; CFDataRef data = ""> do { if (_outputStream==nil) break;
// retrieve native socket handle from output stream. if((data = "" kCFStreamPropertySocketNativeHandle))== NULL) break;
CFSocketNativeHandle socket; CFDataGetBytes(data, CFRangeMake(0, sizeof(CFSocketNativeHandle)), (UInt8*)&socket); . . . // --- here I work with the native socket properties. . } while (false);
if(data!= NULL) ::CFRelease(data); return oss; }
My questions are:
1. What is the lifespan of the native socket handle? 2. Can I retrieve it once, when the socket is created or opened the first time, then use it until socket is closed, or should I retrieve it from the stream like this, every time I want to use it? 3. What is the cost of the above lines that retrieve the native socket handle? Thanks! Motti Shneor. ---------------------------------------- Ceterum censeo Microsoftinem delendam esse |