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