Re: CFRead/WriteStreamClose hoops thread
Re: CFRead/WriteStreamClose hoops thread
- Subject: Re: CFRead/WriteStreamClose hoops thread
- From: Eli Bach <email@hidden>
- Date: Fri, 31 Oct 2008 19:03:03 -0700
Just to follow up on this, it turned out to be a retaincount problem.
When you create each stream, rc=1, then when you schedule them on the
runloop and open them, rc increases to 3.
If you release "your" retain before unscheduling it from the runloop
OR call streamclose, the calls will hang
So, if you call either CF...StreamUnscheduleFromRunLoop() or
CF...StreamClose() when the retaincount of the object is 2, the
function calls will hang. Nothing is logged with either the 'regular'
or debug versions of the 10.5 frameworks.
Radar Number: 6337488
Eli
On Oct 28, 2008, at 6:51 PM, Eli Bach wrote:
I've created read/write streams, hooked them both to the same
runloop, which is the CFRunLoop of the main thread of a cocoa app.
I've written data out, and received responses fine.
For starting up the connection (ripped out from the call chain):
// TODO: should we switch to using
CFStreamCreatePairWithSocketToCFHost instead of
CFStreamCreatePairWithSocketToHost?
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault,
connectToHost->m_ServerAddress.Get(),
connectToHost->m_ServerPort,
&localReadStream, &localWriteStream);
result = CFReadStreamSetProperty(readStream.Get(),
kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
result = CFWriteStreamSetProperty(writeStream.Get(),
kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
CFRunLoopRef currentRunLoop = CFRunLoopGetCurrent();
CFReadStreamScheduleWithRunLoop(readStream.Get(), currentRunLoop,
kCFRunLoopCommonModes);
CFWriteStreamScheduleWithRunLoop(writeStream.Get(), currentRunLoop,
kCFRunLoopCommonModes);
succeeded = CFReadStreamOpen(readStream.Get());
succeeded = CFWriteStreamOpen(writeStream.Get());
Now, on tearing down the connection, I have this:
streamStatus = CFReadStreamGetStatus(readStream);
if ((streamStatus != kCFStreamStatusNotOpen)
and (streamStatus != kCFStreamStatusClosed)
and (streamStatus != kCFStreamStatusError))
{
CFReadStreamClose(readStream);
}
if (currentRunLoop != nil)
{
CFReadStreamUnscheduleFromRunLoop(readStream, currentRunLoop,
kCFRunLoopCommonModes);
}
CFReadStreamSetClient(readStream, kCFStreamEventNone, nil, nil);
readStream.Release();
(and the same code for the write stream)
Right now, it does something crazy to the thread when it enters
CFReadStreamClose().
It doesn't return from the function, and if the thread is paused,
the stack just has a couple of ?? entries.
Other threads continue to work fine (as I happen to be doing some
processing in another thread as this stream is being closed), but
the main thread is stopped at this point.
Any ideas?
_______________________________________________
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