请问shesh用这个函数如何才能设置recv函数超时?

解决方案 »

  1.   

    //等待可写,0表示成功,SOCKET_ERROR表示错误
    int CSimpleSocket::waitforread(int milliseconds)
    {
            fd_set set;
            FD_ZERO(&set);
            FD_SET(handle, &set);        struct timeval timeOut;
            timeOut.tv_sec = 0;
            timeOut.tv_usec = milliseconds * 1000;        int result = select(0, &set, NULL, NULL, &timeOut);        if(result == 0)
            {
                    WSASetLastError( WSAETIMEDOUT );
                    result = SOCKET_ERROR;
            }
            else if(result != SOCKET_ERROR)
                    result = 0;        return result;
    }