I have a server app which creates an object for every client that connects. In this object's init
method I use this code to create a CFSocket
to communicate with the client:
CFSocketContext context = {
.info = self
};
socket = CFSocketCreateWithNative( kCFAllocatorDefault, nativeSocket, kCFSocketDataCallBack, SocketCallback, &context );
source = CFSocketCreateRunLoopSource( kCFAllocatorDefault, socket, 0 );
CFRunLoopAddSource( CFRunLoopGetMain(), source, kCFRunLoopCommonModes );
When the main program is done with the client it releases the ClientConnection
object and it's dealloc
method gets called:
CFSocketDisableCallBacks( socket, kCFSocketDataCallBack );
CFRunLoopRemoveSource( CFRunLoopGetMain(), source, kCFRunLoopCommonModes );
CFRelease( source );
CFSocketInvalidate( socket );
CFRelease( socket );
After that is done I still receive data callbacks which get routed to the now deallocated object which causes a crash.
I tried everything I can think off, but I still can't make this work. Any ideas about why the CFSocket
is sending callbacks after it has been invalidated?