I want to connect with pool.ntp.org to time sync. So am creating a socket
sock=CFSocketCreate(NULL, PF_INET, SOCK_DGRAM, IPPROTO_UDP, kCFSocketDataCallBack|kCFSocketWriteCallBack|kCFSocketConnectCallBack, sockCallback, &sock_ctx);
then am setting up a loop
sockref=CFSocketCreateRunLoopSource(NULL, sock, 0);
CFRunLoopAddSource(CFRunLoopGetMain(), sockref, kCFRunLoopCommonModes);
and connecting to the address
CFDataRef adrref=CFDataCreate(NULL, (const UInt8 *)&adr, sizeof(adr));
CFSocketError err=CFSocketConnectToAddress(sock, adrref,-1);
if i have callback kCFSocketWriteCallBack i send the required data
CFDataRef bufref=CFDataCreate(NULL, buffer, scl->NTP_PACKET_SIZE);
CFSocketError error = CFSocketSendData(scl->sock, NULL, bufref,3);
everything until here works perfect.My actual problem is at
else if(callbackType==kCFSocketDataCallBack)
9/10 times is working ok. server sending the response and my process continues. the problem is that am waiting for data to come to actual continue my app logic. if no data come kCFSocketDataCallBack
is not triggered and app waiting for ever. Is there a way for me to put a timeout at waiting to receive data?( without having by myself a NSTimer
to reconnect to the pool)