Re: CLOSE_WAIT with CFHTTPMessage
Re: CLOSE_WAIT with CFHTTPMessage
- Subject: Re: CLOSE_WAIT with CFHTTPMessage
- From: Mark Pauley <email@hidden>
- Date: Thu, 24 Jun 2010 13:05:28 -0700
What OS are you running with?
On Jun 24, 2010, at 11:53 AM, Greg Hulands wrote:
> Hi Mark,
> I didn't have the connection: close header but did have
>
> CFReadStreamSetProperty(_readStreamRef, kCFStreamPropertyHTTPAttemptPersistentConnection, kCFBooleanFalse)
>
> I added the connection: close header, but still see the same bevhaviour of the sockets not closing. netstat shows them with both send and receive queues empty.
>
> I am definitely calling CFReadStreamClose.
>
> Thanks,
> g
>
> On Jun 24, 2010, at 11:37 AM, Mark Pauley wrote:
>
>> What version of the OS are you running? I'm guessing that you're not setting the Connection: Close header and / or you're setting the keep-alive property on the connection, correct?
>>
>> In general: to use connection keep alive with HTTP Read Streams, you have to overlap open's and close's. This means that you can unschedule and set the client to NULL, but you can't call CFReadStreamClose until you open the next read stream. Keep the previous read stream in an instance variable or something and close it after you open the next request. Of course when you want to actually kill the underlying connection, you can call CFReadStreamClose before opening the next stream.
>> Using keepalive should be a huge performance win for you as well.
>>
>> Apart from that, if you can prove that you're actually calling CFReadStreamClose and we aren't closing your socket, and you see the socket in CLOSE_WAIT via 'netstat -p tcp', it would appear you've also hit a bug.
>>
>> PS:
>> What are you really passing to CFSocketInvalidate? The signature is:
>>
>> void CFSocketInvalidate (
>> CFSocketRef s
>> );
>>
>>
>> you don't need to invalidate any sockets... HTTPReadStream will do that for you when you call CFReadStreamClose.
>>
>>
>> _Mark
>>
>> On Jun 24, 2010, at 10:42 AM, Greg Hulands wrote:
>>
>>> Hi,
>>> I'm trying to track down a problem with my app not closing the sockets when using CFHTTPMessageCreateRequest(). Once the request has finished loading I clean things up with the following:
>>>
>>> - (void)finishLoad {
>>> if (_readStreamRef) {
>>> CFReadStreamSetClient(_readStreamRef, kCFStreamEventNone, NULL, NULL);
>>> CFReadStreamUnscheduleFromRunLoop(_readStreamRef, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
>>> CFReadStreamClose(_readStreamRef);
>>> CFSocketInvalidate();
>>> CFRelease(_readStreamRef);
>>> _readStreamRef = NULL;
>>> }
>>> isFinished = YES;
>>> }
>>>
>>> Because my app can upload a couple of thousand file in one session, I am running out of file descriptors. Is there something that I'm not doing to get the underlying socket to close properly?
>>>
>>> thanks,
>>> Greg
>>>
>>> _______________________________________________
>>> 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
>>
>
_______________________________________________
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