Hi, I have CFNework code that sets up a listening socket to accept incoming connection requests. It has been working fine when built against sdk10.3 using Xcode 2.4.1. I recently ported the supporting app to Intel against sdk10.4. The PPC built of the CFNetwork code works fine , but the Intel CFNetwork code doesn't respond to any connection requests. Here is the code. The "OpenListener" code executes with no error. There is no response to connection requests in the "ServerCall" code. I've tried the listenPort integer as both little and big endian with no luck.
I would really appreciate any help to get this to work on Intel. Thanks, Jeff
// --------------------------------------------------------------------------------- // • OpenListener [public] // --------------------------------------------------------------------------------- OSStatus Network::OpenListener(UInt16 listenPort) { CFOptionFlags flags = kCFSocketAcceptCallBack; CFSocketContext context = {0,this,nil,nil,nil}; CFSocketError err = kCFSocketError; CFDataRef address; struct sockaddr_in addrs = {8,AF_INET,CFSwapInt32BigToHost(listenPort),{0}};
mListenSocket = CFSocketCreate(nil,PF_INET,SOCK_STREAM,IPPROTO_TCP,flags,ServerCallBack,&context); if(mListenSocket != nil) { RetainCt(this); int yes = 1; setsockopt(CFSocketGetNative(mListenSocket),SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)); mListenRunLoopSrc = CFSocketCreateRunLoopSource(nil, mListenSocket, 0); if(mListenRunLoopSrc) { CFRunLoopAddSource(CFRunLoopGetCurrent(), mListenRunLoopSrc, kCFRunLoopCommonModes); address = CFDataCreateWithBytesNoCopy(nil,(UInt8*)&addrs, sizeof(addrs), kCFAllocatorNull); if(address) { err = CFSocketSetAddress(mListenSocket, address); CFRelease(address); } } } return err; } // --------------------------------------------------------------------------------- // • ServerCallBack [public] // --------------------------------------------------------------------------------- void Network::ServerCallBack(CFSocketRef s, CFSocketCallBackType type, CFDataRef address, const void *data, void *info) { Network* objRef = (Network*)info; objRef->ServerCall( s, type, address, data); } // --------------------------------------------------------------------------------- // • ServerCall [public] // --------------------------------------------------------------------------------- void Network::ServerCall(CFSocketRef s, CFSocketCallBackType type, CFDataRef address, const void *nativeSocketH) { #pragma unused(s) struct sockaddr_in* aptr; Network* net = nil; UInt32 peerAddress = 0; SInt32 err; switch(type) { case kCFSocketAcceptCallBack: if(address != nil) { aptr = (struct sockaddr_in*)CFDataGetBytePtr(address); peerAddress = aptr->sin_addr.s_addr; } net = AcceptConnectionSelf(peerAddress); if(net != nil) { if(net->AcceptConnection(address,*((CFSocketNativeHandle*)nativeSocketH)) == false) { delete net; net = nil; } } if(net == nil) { err = shutdown(*(int*)nativeSocketH, SHUT_RDWR); err = close(*(int*)nativeSocketH); } break; default: break; } } // ---------------------------------------------------------------------------------
|