• 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
Re: Using CFSocket to connect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using CFSocket to connect


  • Subject: Re: Using CFSocket to connect
  • From: Mike Laster <email@hidden>
  • Date: Fri, 05 Jul 2002 11:40:31 -0400

Still having problems. I can get blocking connects to work, but
non-blocking connects never seem to trigger the callback (though they
actually DO connect according to my server).

Here is a snippit of my code:

socketRef = CFSocketCreate(NULL,PF_INET,
SOCK_STREAM,
IPPROTO_TCP,
kCFSocketDataCallBack|kCFSocketConnectCallBack,
MCFSocketCallback,
&socketContext);

if (socketRef != NULL)
{
NSRunLoop *rl = [NSRunLoop currentRunLoop];
NSDate *limitDate = [NSDate dateWithTimeIntervalSinceNow:10.0];
NSTimeInterval limitTimeInterval = [limitDate
timeIntervalSinceReferenceDate];

[MLog logWithFormat:@"now=%@ (%f) limit=%@ (%f)", [NSDate date],
[NSDate timeIntervalSinceReferenceDate],
limitDate, limitTimeInterval];
// fire off a background connection attempt
[MLog logWithFormat:@">>> kicking off background connect"];
CFSocketConnectToAddress(socketRef,[[[self parentPair] remote]
socketSignature].address, -10);
[MLog logWithFormat:@"<<< kicking off background connect"];

[MLog logWithFormat:@"Run the run loop until %@", limitDate];
while ([NSDate timeIntervalSinceReferenceDate] < limitTimeInterval)
{
[MLog logWithFormat:@"limitTimeInterval: %f now: %f",
limitTimeInterval, [NSDate timeIntervalSinceReferenceDate]];
[MLog logWithFormat:@">>> run submode"];
[rl runMode:NSDefaultRunLoopMode beforeDate:limitDate];
[MLog logWithFormat:@"<<< run submode"];

}


The output of this code is:

D: (07-05 11:37:41.476) now=2002-07-05 11:37:41 -0400 (47576261.476427)
limit=2002-07-05 11:37:51 -0400 (47576271.476406)
D: (07-05 11:37:41.478) >>> kicking off background connect
D: (07-05 11:37:41.484) <<< kicking off background connect
D: (07-05 11:37:41.486) Run the run loop until 2002-07-05 11:37:51 -0400
D: (07-05 11:37:41.488) limitTimeInterval: 47576271.476406 now:
47576261.488333
D: (07-05 11:37:41.490) >>> run submode
D: (07-05 11:37:42.396) *TICK*
D: (07-05 11:37:43.399) *TICK*
D: (07-05 11:37:44.397) *TICK*
D: (07-05 11:37:45.396) *TICK*
D: (07-05 11:37:46.397) *TICK*
D: (07-05 11:37:47.397) *TICK*
D: (07-05 11:37:48.406) *TICK*
D: (07-05 11:37:49.535) *TICK*
D: (07-05 11:37:50.397) *TICK*
D: (07-05 11:37:51.613) *TICK*
D: (07-05 11:37:51.615) <<< run submode


I have a 1 second timer scheduled in the main run loop to print "*TICK*"
just so that I can detect when I'm blocking the run loop. In this case I'm
not. It runs for the full 10 seconds, and the callback never happens.
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Using CFSocket to connect
      • From: Mike Laster <email@hidden>
References: 
 >Re: Using CFSocket to connect (From: Douglas Davidson <email@hidden>)

  • Prev by Date: Re: CFStream bugs? (was Re: CFNetwork Website)
  • Next by Date: CFReadStreamGetBuffer doesn't work for HTTP streams?
  • Previous by thread: Re: Using CFSocket to connect
  • Next by thread: Re: Using CFSocket to connect
  • Index(es):
    • Date
    • Thread