为什么我的选择功能不起作用?它的返回 -1 和错误代码是 10038

问题描述

我的选择函数在我的服务器代码中返回 -1,并在检查错误代码时返回 10038,文档中有此描述:- WSAENOTSOCK 10038 非套接字上的套接字操作。 试图对不是套接字的东西进行操作。套接字句柄参数未引用有效套接字,或者对于 select,fd_set 的成员无效。

我的代码

nRet = select(nSocket + 1,&fr,&fw,&fe,&tv);
if (nRet > 0)
{
    //someone connects or communicates with a message over a dedicated connection
    std::cout << "data on port\n";
    ProcessRequest();
}
else
{
    if (nRet == 0)
    {
        //No connection or any communication made or you can say that none of the descriptors
        //are ready
        std::cout << "nothing on port:" << PORT << "\n";
    }
    else
    {
        //it Failed to connect
        std::cout << "it Failed" << nRet << "\n";
        error = WSAGetLastError();
        std::cout << "error: " << error << "\n";
                
        WSACleanup();
        exit(EXIT_FAILURE);
    }
}

仅用于清除 socket()、setsockopt()、bind() 和 listen() 调用成功,因为它们返回 1

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)