在我的程序里有如下一段代码,在异步事件FD_ACCEPT里面发送、接收了数据,请是否可行,如不可行,我需要接收两组数据当如何设计? case FD_ACCEPT:
struct sockaddr_in otherhost; //the other host address
int otherhost_s; //the socket of other_connect host
struct sockaddr_in *temphost; //used to receive bisection host info
namelen = sizeof(otherhost);
//accept the connection
if ((otherhost_s = accept(s, (struct sockaddr *)&otherhost, &namelen)) == INVALID_SOCKET)
{
MessageBox("Error in Accept()");
return;
}
//receive bisection host infomation
if(recv(otherhost_s, buf, namelen, 0) != namelen)
{
MessageBox("Fail to recv the bisection host info!");
} //add this host to localhost connect queue
temphost = (struct sockaddr_in *)buf;
connectQ[i++] = *temphost; //send the connect queue to bisection
if( send(otherhost_s, (char*)connectQ, consize, 0) != consize)
{
MessageBox("Fail to send connect queue!");
break;
} set_socket(hWnd, otherhost_s, FD_READ|FD_CLOSE);
break;
struct sockaddr_in otherhost; //the other host address
int otherhost_s; //the socket of other_connect host
struct sockaddr_in *temphost; //used to receive bisection host info
namelen = sizeof(otherhost);
//accept the connection
if ((otherhost_s = accept(s, (struct sockaddr *)&otherhost, &namelen)) == INVALID_SOCKET)
{
MessageBox("Error in Accept()");
return;
}
//receive bisection host infomation
if(recv(otherhost_s, buf, namelen, 0) != namelen)
{
MessageBox("Fail to recv the bisection host info!");
} //add this host to localhost connect queue
temphost = (struct sockaddr_in *)buf;
connectQ[i++] = *temphost; //send the connect queue to bisection
if( send(otherhost_s, (char*)connectQ, consize, 0) != consize)
{
MessageBox("Fail to send connect queue!");
break;
} set_socket(hWnd, otherhost_s, FD_READ|FD_CLOSE);
break;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货