• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
A NSOutputStream vs. native socket question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A NSOutputStream vs. native socket question


  • Subject: A NSOutputStream vs. native socket question
  • From: Motti Shneor <email@hidden>
  • Date: Thu, 14 Nov 2013 20:53:24 +0200

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


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: A NSOutputStream vs. native socket question
      • From: Josh Graessley <email@hidden>
  • Prev by Date: Re: Wi-Fi network can't see Bonjour services on wired network
  • Next by Date: Re: A NSOutputStream vs. native socket question
  • Previous by thread: Re: Wi-Fi network can't see Bonjour services on wired network
  • Next by thread: Re: A NSOutputStream vs. native socket question
  • Index(es):
    • Date
    • Thread