title: Why does CFStreamCreatePairWithSocketToCFHost fail when CFStreamCreatePairWithSocketToHost succeeds
body: <p>On iOS6.1, the following code should do the very same thing, but when I forgot to write <code>addr.sin_len = sizeof(adde)</code> the first block failed. The original error was:</p>
  
  <pre><code>GOT EVENT FROM INPUT Event: 8
  ERR: Error Domain=NSPOSIXErrorDomain Code=12 "The operation couldn’t be completed. Cannot allocate memory"
  </code></pre>
  
  <p>After adding in the missing line to set the struct size, the first block worked just as the second. Probably other developers will see that error message and trip on this post.</p>
  
  <p>The code:</p>
  
  <pre><code>    CFReadStreamRef readStream = NULL;
      CFWriteStreamRef writeStream = NULL;
  
  #if 1 // LONG WAY
      struct sockaddr_in addr;
      memset(&amp;addr, 0, sizeof(addr));
      addr.sin_len        = sizeof(addr);  // ORIGINALLY WAS MISSING
      addr.sin_family     = AF_INET;
      addr.sin_port       = htons(5566);
      int ret = inet_pton(AF_INET, "192.168.1.2", &amp;(addr.sin_addr.s_addr)); // IPv4
      assert(ret == 1);
  
      NSLog(@"CONNECT");
      CFDataRef address = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)&amp;addr, sizeof(addr));
      assert(address);
  
      CFHostRef macMini = CFHostCreateWithAddress(kCFAllocatorDefault, address);
      CFRelease(address);
      assert(macMini);
  
      // (tried, makes not difference) CFHostScheduleWithRunLoop (macMini, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
  
      CFStreamCreatePairWithSocketToCFHost(kCFAllocatorDefault, macMini, 5566, &amp;readStream, &amp;writeStream);
      CFRelease(macMini);
  #else // SHORT WAY
      CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, CFSTR("192.168.1.2"), 5566, &amp;readStream, &amp;writeStream);
  #endif
  
      assert(readStream);
      assert(writeStream);
  
      iStream = CFBridgingRelease(readStream);
      oStream = CFBridgingRelease(writeStream);
  
      [iStream setDelegate:self];
      [iStream scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
      [iStream open];
      NSLog(@"ISTREAM %@ status=%d", iStream, [iStream streamStatus]);
      NSLog(@"ERR: %@", [iStream streamError]);
  
      [oStream setDelegate:self];
      [oStream scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
      [oStream open];
      NSLog(@"OSTREAM %@ status=%d", oStream, [oStream streamStatus]);
      NSLog(@"ERR: %@", [oStream streamError]);
  </code></pre>