• 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
streams/sockets slow to close?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

streams/sockets slow to close?


  • Subject: streams/sockets slow to close?
  • From: Michael Brian Bentley <email@hidden>
  • Date: Thu, 14 Nov 2013 12:04:49 -0800

I've asked more or less the same question on the CocoaAsyncSocket list, but posting it here may be more appropriate.

I have been following what Apple recommended to write some code for an iOS app. It sets up an NSInputStream from a 
CFReadStreamRef and an NSOutputStream from a CFWriteStreamRef using CFStreamCreatePairWithSocketToHost, CFReadStreamSetProperty and CFWriteStreamSetProperty. Then schedule the NSInputStream and NSOutputStream in the run loop, set SSL, and open. And I have a nice stream event handler set up. Now, I use the SetProperty calls to assert

kCFStreamPropertyShouldCloseNativeSocket to kCFBooleanTrue.

Something isn't quite right, so I've been studying AsyncSocket.m and .h.


Running my project, I'll see lots of these using tcpdump:

15:39:10.015118 IP x > y: Flags [S], seq 3528420243, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 918649874 ecr 0,sackOK,eol], length 0

Then I close the streams. Nothing appears to happen for a while.

Then some latent packet traffic shows up well after the close. Note the time stamps:

15:39:53.300403 IP x > y: Flags [FP.], seq 1:159, ack 1, win 8208, options [nop,nop,TS val 918692976 ecr 114019195], length 158

15:40:57.495343 IP x > y: Flags [FP.], seq 1:159, ack 1, win 8208, options [nop,nop,TS val 918756995 ecr 114019195], length 158

15:42:01.739991 IP x > y: Flags [FP.], seq 1:159, ack 1, win 8208, options [nop,nop,TS val 918821075 ecr 114019195], length 158

15:43:05.942109 IP x > y: Flags [FP.], seq 1:159, ack 1, win 8208, options [nop,nop,TS val 918885076 ecr 114019195], length 158

15:44:10.165363 IP x > y: Flags [FP.], seq 1:159, ack 1, win 8208, options [nop,nop,TS val 918949118 ecr 114019195], length 158

15:45:14.477259 IP x > y: Flags [R.], seq 160, ack 1, win 8208, length 0


There appears to be quite a lot of time going by for everything to settle. Is there any way to move things along? I noticed that the AsyncSocket.m code makes sure that the CFSocket is closed explicitly if it is still around.

-Mike

 _______________________________________________
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: streams/sockets slow to close?
      • From: "Quinn \"The Eskimo!\"" <email@hidden>
    • Re: streams/sockets slow to close?
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: A NSOutputStream vs. native socket question
  • Next by Date: Re: streams/sockets slow to close?
  • Previous by thread: Re: A NSOutputStream vs. native socket question
  • Next by thread: Re: streams/sockets slow to close?
  • Index(es):
    • Date
    • Thread