rayyt
2018-02-04 08:39
采纳率: 50%
浏览 2.2k
已采纳

openssl的BIO方式如何设置ssl连接超时?

代码如下:但是感觉没啥作用。
BIO_set_nbio(bio,1);
DEBUG_INFO;
/* Create and setup the connection */
BIO_set_conn_ip(bio,argv[1]);
BIO_set_conn_port(bio,argv[2]);
int flag=0;
ret= BIO_do_connect(bio);
if(ret<=0&&!BIO_should_retry(bio))
{
printf("failed to establish connection\n");
return 0;
}
if(BIO_get_fd(bio,&sockfd)<0)
{
printf("failed to get fd\n");
return 0;
}
if(ret<=0)
{
FD_ZERO(&connectionfds);
FD_SET(sockfd, &connectionfds);
timeout.tv_usec = 0;
timeout.tv_sec = TIMEOUT;
if(select(sockfd+1,NULL,&connectionfds,NULL,&timeout)==0)
{
flag=0;
}

    }
    else
    {
            flag=1;
    }

    BIO_set_nbio(bio,0);

if(1==flag)
{
printf("Connect successfully !\n");
ShowCerts(ssl,argv[1],atoi(argv[2]));
}
else
{
printf("time out !\n");

    }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • blownewbee 2018-02-04 16:20
    已采纳
    点赞 打赏 评论

相关推荐 更多相似问题