0
回答
iphone设置非阻塞模式socket两种方法
滴滴云服务器,限时包月0.9元,为开发者而生>>>   

1. ioctl()

/* set socket to non-blocking i/o */ 
sts = ioctl(ccp->main_sock, FIONBIO, (char *)&one); 
if (sts) 
{ 
setproderr(PE_TCPERROR, GEL_FATAL); 
sprintf(line,"ioctl (main) failed - %s",strerror(errno)); 
tcpabort(); 
}
 

 

2.fcntl()

/* Set socket to non-blocking */ 
if ((flags = fcntl(sock_descriptor, F_GETFL, 0)) < 0) 
{ 
/* Handle error */ 
} 

if (fcntl(socket_descriptor, F_SETFL, flags | O_NONBLOCK) < 0) 
{ 
/* Handle error */ 
} 
/* Set socket to blocking */ 
if ((flags = fcntl(sock_descriptor, F_GETFL, 0)) < 0) 
{ 
/* Handle error */ 
} 

if (fcntl(socket_descriptor, F_SETFL, flags & (~O_NONBLOCK)) < 0) 
{ 
/* Handle error */ 
} 
 


原文链接:http://blog.csdn.net/favormm/article/details/5253579
<无标签>
举报
长平狐
发帖于5年前 0回/262阅
顶部