Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ SSL_connect()不与select()一起工作_C++_Sockets_Networking_Openssl_Nonblocking - Fatal编程技术网

C++ SSL_connect()不与select()一起工作

C++ SSL_connect()不与select()一起工作,c++,sockets,networking,openssl,nonblocking,C++,Sockets,Networking,Openssl,Nonblocking,我有一个非阻塞套接字,我正在使用openssl创建ssl连接。我的问题是SSL_connect的工作方式。它返回SSL\u ERROR\u WANT\u READ或SSL\u ERROR\u WANT\u WRITE。在这些情况下,必须再次调用SSL\u connect。现在这真的起作用了。我遇到的问题是,应该让程序等待套接字就绪的select()没有工作。这导致2000多个对SSL_connect的调用,这并不好 这是我这部分程序的代码 int test = 0; while

我有一个非阻塞套接字,我正在使用openssl创建ssl连接。我的问题是SSL_connect的工作方式。它返回SSL\u ERROR\u WANT\u READ或SSL\u ERROR\u WANT\u WRITE。在这些情况下,必须再次调用SSL\u connect。现在这真的起作用了。我遇到的问题是,应该让程序等待套接字就绪的select()没有工作。这导致2000多个对SSL_connect的调用,这并不好

这是我这部分程序的代码

 int test = 0;
        while (test != 1) {
            test = SSL_connect(sslHandle);
            if (test != 1) { //test again or we would quit if we made a connection
                if (SSL_get_error(sslHandle, test) != SSL_ERROR_WANT_READ && SSL_get_error(sslHandle, test) != SSL_ERROR_WANT_WRITE) {
                    //error happend
                    return -1;
                }
                FD_ZERO(&socketSet); //reset socketSet
                FD_SET(socket, &socketSet); //init socketSet with our socket
                if (test == SSL_ERROR_WANT_READ) {

                    result = select(socket + 1, &socketSet, NULL, NULL, &timeoutCopy); //wait for the socket to be readable
                    if (result == 0) {
                        //timeout
                        return -1; 
                    } else if (result == -1) {
                        //error
                        return -1;
                    }


                } else {

                    result = select(socket + 1, NULL, &socketSet, NULL, &timeoutCopy); //wait for the socket to be writable
                    if (result == 0) {
                       //timeout
                        return -1; 
                    } else if (result == -1) {
                       //error
                        return -1; 
                    }

                }

            }
        }
我在这里删除了所有错误处理的内容和日志,因此可读性更好。timeoutCopy在别处定义。我对程序的其他部分使用了相同的选择,它工作得很好。 正如我所说的,程序正在运行,但只是没有在select上等待。我可以睡一觉,但这不是个好办法。提前谢谢

好吧,我是个傻瓜。 问题是一致的

 if (test == SSL_ERROR_WANT_READ) 
这是必须的

if (SSL_get_error(sslHandle, sslConnectResult) == SSL_ERROR_WANT_READ) 
然后代码就可以正常工作了。它迭代4到5次,然后连接