I am creating a socket tcp connection using CFStreamCreatePairWithSocketToHost
like this to get a write stream (I dont want to ready any data):
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)host, port, NULL, &writeStream);
This works pretty well but because of the nagle's algorithm my tcp commands are buffered. This may be cool but in my case I need to send the command as fast as possible without any delays.
I found a way to disable this "feature" using the following code found here:
int yes = 1;
setsockopt(CFSocketGetNative(aSocket), IPPROTO_TCP, TCP_NODELAY, (void *)&yes, sizeof(yes));
but I cant figure out how to get a valid reference to my socket. Can you help me?
CFDataRef socketData = CFWriteStreamCopyProperty(writeStream, kCFStreamPropertySocketNativeHandle);
CFSocketNativeHandle handle;
CFDataGetBytes(socketData, CFRangeMake(0, sizeof(CFSocketNativeHandle)), &handle);
// handle now contains the same thing as CFSocketGetNative(aSocket)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With