SSL_connect返回-1的一种原因是因为socket设置成了非阻塞模式,应设置为阻塞模式。
SSL_library_init();
ERR_load_BIO_strings();
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
SetMMOSocketOption(MMO_SOCKOPT_NONBLOCK,0);
m_pSSLCtx = SSL_CTX_new( SSLv23_client_method() );
m_pSSL = SSL_new(m_pSSLCtx);
==========================================
SetMMOSocketOption(MMO_SOCKOPT_NONBLOCK,0);
「
#ifdef WIN32
result = ioctlsocket (m_iSocket, FIONBIO, (u_long*)&value);
#else
//ioctl(m_socket, FIONBIO, &result);
int flag = fcntl(m_iSocket, F_GETFL,0);
if (flag < 0)
{
result = -1;
break;
}
else
{
if (value == 1)
{
flag |= O_NONBLOCK;
result = fcntl (m_iSocket, F_SETFL, flag);
}
else
{
flag &= ~O_NONBLOCK;
result = fcntl (m_iSocket, F_SETFL, flag);
}
}
#endif
」