CSocket callback keeps giving my Data instead of Read
CSocket callback keeps giving my Data instead of Read
- Subject: CSocket callback keeps giving my Data instead of Read
- From: Ken Baer <email@hidden>
- Date: Thu, 6 Oct 2005 17:39:13 -0700
I am implementing a port of WinSock to the Mac using BSD sockets, and I have a function that is setting up the network event callbacks. I am creating a CFSocket from the SOCKET, setting up the callback types, creating a runloop source and adding it to the runloop. I have even taken steps to set the socket flags with CFSocketSetSocketFlags() to no automatically reenable the kCFSocketDataCallBack, and also called CFSocketDisableCallBacks() for kCFSocketDataCallBack.
I am getting callbacks, like Connect, and Write, but the problem is that I get kCFSocketDataCallBack, and NOT kCFSocketReadCallBack. My code wants to use the Read method, not the buffered Data method. Somehow it keeps getting turned on, even after I told it not to (bad, bad CFSocket!). Here is the code segment I am using to set this up. Is there another step to assure that it uses the Read callback and not the Data callback?
CFOptionFlags callBackTypes = 0, autocallbacktypes = 0;
// build event flags
if (lEvent & FD_READ) {
callBackTypes |= kCFSocketReadCallBack;
autocallbacktypes |= kCFSocketAutomaticallyReenableReadCallBack;
}
if (lEvent & FD_WRITE) {
callBackTypes |= kCFSocketWriteCallBack;
autocallbacktypes |= kCFSocketAutomaticallyReenableWriteCallBack;
}
if (lEvent & FD_ACCEPT) {
callBackTypes |= kCFSocketAcceptCallBack;
autocallbacktypes |= kCFSocketAutomaticallyReenableAcceptCallBack;
}
if (lEvent & FD_CONNECT)
callBackTypes |= kCFSocketConnectCallBack;
if (!(socket->m_cfsocket = CFSocketCreateWithNative( NULL, s, callBackTypes, (CFSocketCallBack)&SocketCallBack, NULL)))
return SOCKET_ERROR;
// make sure underlying SOCKET isn't clobbered when CFSocket invalidated, and make sure DataCallBack is not automatically reenabled
CFSocketSetSocketFlags( socket->m_cfsocket, autocallbacktypes | kCFSocketCloseOnInvalidate );
CFSocketDisableCallBacks( socket->m_cfsocket, kCFSocketDataCallBack ); // we REALLY don't want these
if (!(socket->m_runloopsource = CFSocketCreateRunLoopSource(NULL, socket->m_cfsocket, 0))) {
CFRelease( socket->m_cfsocket );
socket->m_cfsocket = NULL;
return SOCKET_ERROR;
}
CFRunLoopAddSource((CFRunLoopRef)GetCFRunLoopFromEventLoop(GetMainEventLoop()), socket->m_runloopsource, kCFRunLoopCommonModes);
-Ken Baer.
Hash, Inc.
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