当前位置: 技术问答>linux和unix
奇怪的socket问题,关于如何设置send非阻塞
来源: 互联网 发布时间:2016-09-20
本文导语: while(1) { timeout.tv_sec = 10; timeout.tv_usec = 0; FD_ZERO(&readfds); FD_SET(newsockfd,&readfds); rt = select(newsockfd + 1,&readfds,NULL,NULL,&timeout); if(rt == SOCKET_ERROR) { printf("socket error when select! n"); break; } else { if(...
while(1)
{
timeout.tv_sec = 10;
timeout.tv_usec = 0;
FD_ZERO(&readfds);
FD_SET(newsockfd,&readfds);
rt = select(newsockfd + 1,&readfds,NULL,NULL,&timeout);
if(rt == SOCKET_ERROR)
{
printf("socket error when select! n");
break;
}
else
{
if(FD_ISSET(newsockfd,&readfds))
{
if(flag == 0)
{
if(recv(newsockfd,&sd_communication_header_variable,sizeof(sd_communication_header_variable),0) > 0)
{
if(!read_profile_string("Version","CurrentVersion",ini,BUF_SIZE,"",inifile_chanpin))
{
printf("read ini file failn");//这里可能因为多线程的原因显示不出来,BUF_SIZE的大小也要考虑,不能全部4100
return;
}
else
{
if(ProductVersionisOk(ini,sd_communication_header_variable.dwProductVersion) != 0)
{
printf("%ld n",sd_communication_header_variable.dwProductVersion);
printf("%ld n",sd_communication_header_variable.dwCmdID);
printf("客户端与服务器版本不正确!n");
return;
}
}
timeout.tv_sec = 10;
timeout.tv_usec = 0;
FD_ZERO(&readfds);
FD_SET(newsockfd,&readfds);
rt = select(newsockfd + 1,&readfds,NULL,NULL,&timeout);//这边是send的select
if(rt == SOCKET_ERROR)
{
printf("socket error when select! n");
break;
}
if(send(newsockfd,"I got your message",18,0)