CFRead/WriteStreamClose hoops thread
CFRead/WriteStreamClose hoops thread
- Subject: CFRead/WriteStreamClose hoops thread
- From: Eli Bach <email@hidden>
- Date: Tue, 28 Oct 2008 18:51:29 -0700
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