- 论坛徽章:
- 0
|
- int resultS = ::select(fd + 1, &fdSet, 0, 0, &tv);//使用select()防止拒绝服务型攻击
-
- if(resultS == 0)
- {
- //cout <<"1111"<<endl;
-
-
- if (lenLeft > 0)
- {//部分接收, 超时
- ret_code = COMMON_BSAE_ERROR_NO - 121;
- //printf("In CTransCommonSocket::RecvFromNet, select(%d) timeout error number = %d...\n", fd, ret_code);
- cout <<"In CTransCommonSocket::RecvFromNet, select("<<fd<<") timeout error number = " <<ret_code<<"..."<<endl;
-
-
-
- return ret_code;
- }
- else
- {
- //cout <<"222"<<endl;
- //如果强制无限等待,不进行超时返回
- if( timeout != WAITINFINE ) //一直等待标志
- {
-
- cout <<"timeout"<<timeout<<endl;
- return 0; //未接收, timeout
- }
- else
- {
- //cout <<"In CTransCommonSocket::RecvFromNet, timeout is waitting..."<<endl;
- continue;
- }
-
-
- }
- }
- else if(resultS == -1)
- {
- if(IsInterrupted())
- continue;
- int err=GetError();
-
- ret_code = COMMON_BSAE_ERROR_NO - 122;
- //printf("In CTransCommonSocket::RecvFromNet, select() error number = %d...\n", ret_code);
- cout <<"In CTransCommonSocket::RecvFromNet, select("<<fd<<") error number = " <<ret_code<<",GetError():"<<GetError()<<"..."<<endl;
- return ret_code;
- }
- int result = ::recv(fd_, (char*)(buf + lenLeft), sizeOfPacket, 0);
- if(result == 0)//false, connection closed
- {
- int err=GetError();
-
- ret_code = COMMON_BSAE_ERROR_NO - 123;
- //printf("CTransCommonSocket::RecvFromNet, recv(%d) error number = %d...\n", fd_, ret_code);
- return ret_code;
- }
- else if(result == -1)
- {
- if(NoBufs() && sizeOfPacket > 1024)
- {
- sizeOfPacket /= 2;
- continue;
- }
-
- if(IsInterrupted())
- continue;
- if(fd_ == -1 || ConnectionDown())
- {//false, connection loss
-
- int err=GetError();
-
-
- ret_code = COMMON_BSAE_ERROR_NO - 124;
- printf("In CTransCommonSocket::RecvFromNet, recv() error number = %d, fd = %d...\n", ret_code, fd_);
- return ret_code;
- }
- if(WouldBlock())
- continue;
-
- int err=GetError();
-
-
- ret_code = COMMON_BSAE_ERROR_NO - 125;
- printf("In CTransCommonSocket::RecvFromNet, recv() error number = %d...\n", ret_code);
- return ret_code;
- }
复制代码 不是windows的,标准C下面的 |
|