Outpust stream/Native socket question:
Outpust stream/Native socket question:
- Subject: Outpust stream/Native socket question:
- From: Motti Shneor <email@hidden>
- Date: Thu, 14 Nov 2013 11:33:09 +0200
Hi Everyone.
I'm controlling the output stream created by
::CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)hostAddress, portNum, &readStream, &writeStream);
::CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
::CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
via its internal native socket, using the posix getsockopt and setsockopt calls.
The properties I'm working with are the input and output buffer sizes, and the output socket's buffer 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 the following code.
// 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 = NULL;
do {
if (_outputStream==nil)
break;
// retrieve native socket handle from output stream.
if((data = (CFDataRef)::CFWriteStreamCopyProperty((CFWriteStreamRef)_outputStream, kCFStreamPropertySocketNativeHandle))== NULL)
break;
CFSocketNativeHandle socket;
CFDataGetBytes(data, CFRangeMake(0, sizeof(CFSocketNativeHandle)), (UInt8*)&socket);
.
.
.
} while (false);
if(data!= NULL)
::CFRelease(data);
return oss;
}
My question: What is the lifespan of the native socket handle? Can I retrieve it once, when the socket is created, or opened the first time, and then use it again and again, or should I retrieve it from the stream like this, every time I want to use it?
What is the cost of the above lines that retrieve the native socket handle?
Thanks!
Motti Shneor.
----------------------------------------
Ceterum censeo Microsoftinem delendam esse
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden