PDA

View Full Version : CFSocket Callback Help




Nooshva
Sep 17, 2008, 10:33 AM
Im having one issue that is rather big with using CFSockets in a Server side app --> The code for accepting sockets is as follows


void SocketCallBack (CFSocketRef s,CFSocketCallBackType callbackType,CFDataRef address,const void *data,void *info) {
switch (callbackType) {
case kCFSocketAcceptCallBack:
printf("SocketCallBack -> Type of kCFSocketAcceptCallBack\n");
struct sockaddr_in * theName = (struct sockaddr_in *) CFDataGetBytePtr(address);
CFSocketRef aSocket = CFSocketCreateWithNative(kCFAllocatorDefault,(CFSocketNativeHandle) data,kCFSocketDataCallBack, SocketCallBack,NULL);
if (aSocket) {
printf("Native Socket Created Successfully From Location: %s, Adding to Run Loop for Listening Data\n", inet_ntoa(theName->sin_addr));
CFRunLoopAddSource(CFRunLoopGetCurrent(),CFSocketCreateRunLoopSource(NULL, aSocket, 0),kCFRunLoopDefaultMode);
}
break;
case kCFSocketDataCallBack:
printf("SocketCallBack -> Type of kCFSocketDataCallBack\n");

if (CFDataGetLength(data) <= 0) {
printf("Disconnected!");
CFSocketInvalidate(s);
break;
}

printf("Data Callback Data -> %s\n",CFDataGetBytePtr(data));
break;
default:
printf("SocketCallBack -> Type of UNKNOWN - ID: %i\n", callbackType);
break;
}

}


Everything works fine except for the Client socket callback. (I.E. Connects to server fine) It's not doing a callback when any data is in the buffer. Any Ideas?