读书人

问个网络编程有关问题(,)

发布时间: 2012-05-03 14:06:56 作者: rapoo

问个网络编程问题(求救,在线等!)

C/C++ code
//问题有关于select(事件选择模式)fd_set fdSelect;FD_ZERO(&fdSelect);FD_SET(sockSrv, &fdSelect);while(true){    fd_set fdRead = fdSelect;    int nRet = select(0, &fdRead, NULL, NULL, NULL);    if(nRet > 0)    {        for(int i = 0; i < (int)fdSelect.fd_count; ++i)        {            if(FD_ISSET(fdSelect.fd_array[i], &fdRead))            {//为什么要把未被select处理过的fd_set中的一员与处理过的fd_set做查询呢?                ;            }        }    }}


[解决办法]
探讨
C/C++ code
//问题有关于select(事件选择模式)
fd_set fdSelect;
FD_ZERO(&fdSelect);
FD_SET(sockSrv, &fdSelect);
while(true)
{
fd_set fdRead = fdSelect;
int nRet = select(0, &fdRead, NULL, NULL,……

[解决办法]
触发的事件分为两种,一种是accept接收新的链接后有数据到来,这时候需要比较这个new_client_fd上是否有数据到来,另一种是socket建立后负责listen的fd是否有新的连接请求,如果有就调用accept接收这个新的链接,并把新连接的client_fd放到FD_SET中,等待触发。

读书人网 >C++

热点推荐