1. win
unsigned long ul = 1; //ul为非零是为非阻塞模式
ioctlsocket(socket, FIONBIO, &ul);
2. linux
<pre name="code" class="cpp">void setnonblocking(int sock)
{
int opts;
opts=fcntl(sock,F_GETFL);
if(opts<0)
{
perror("fcntl(sock,GETFL)");
exit(1);
}
opts = opts|O_NONBLOCK;
if(fcntl(sock,F_SETFL,opts)<0)
{
perror("fcntl(sock,SETFL,opts)");
exit(1);
}
}
3. win下setsockopt函数可设置ip复用等一系列属性