Re: CFSocketCreateRunLoopSource crashes
Re: CFSocketCreateRunLoopSource crashes
- Subject: Re: CFSocketCreateRunLoopSource crashes
- From: Jaime Magiera <email@hidden>
- Date: Sun, 24 Aug 2008 09:23:07 -0400
On Aug 24, 2008, at 5:01 AM, Liwei wrote:
Hmm... Somehow the following code crashes while trying to create the
runloop source:
struct sockaddr_in a = {0, AF_INET, htons(5555), 0};
CFDataRef d = CFDataCreate(kCFAllocatorDefault, (UInt8 *)&a,
sizeof(struct sockaddr_in));
CFSocketSignature signature = {PF_INET, SOCK_DGRAM, IPPROTO_UDP, d};
CFSocketRef socket =
CFSocketCreateWithSocketSignature(kCFAllocatorDefault, &signature,
kCFSocketDataCallBack, receiveData, NULL);
CFRunLoopSourceRef source =
CFSocketCreateRunLoopSource(kCFAllocatorDefault, socket, 0);
CFRunLoopRef loop = CFRunLoopGetCurrent();
CFRunLoopAddSource(loop, source, kCFRunLoopDefaultMode);
Hi Liwei,
I responded to you before, not sure if you saw it. Comparing your code
with mine (which works on XCode 3.1/OSX10.5/Intel), it seems our
sockaddr_in structs are different. The struct is defined as...
struct sockaddr_in { short sin_family;
unsigned short sin_port;
struct in_addr sin_addr;
char sin_zero[8]; };
To help keep my structs clear and tidy, I like to explicitly set their
members. In this case...
struct sockaddr_in myAddress;
myAddress.sin_family = AF_INET;
myAddress.sin_port = htons(testPort);
myAddress.sin_addr.s_addr = htonl(INADDR_ANY);
Your structure is created with 4 members, which don't see to be correct.
struct sockaddr_in a = {0, AF_INET, htons(5555), 0};
You have an erroneous member at the beginning. So, you end up passing
"0" as sin_family, "AF_INET" as sin_port and "htons(5555)" as
sin_addr. (Did you intend the last member to be sin_zero?)
Could it be that your code is failing due to this?
Jaime Magiera
Sensory Research
http://www.sensoryresearch.net
_______________________________________________
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