首页 \ 问答 \ C - BIO_get_fd()始终无法获得有效的FD(C - BIO_get_fd() always fails to get a valid FD)

C - BIO_get_fd()始终无法获得有效的FD(C - BIO_get_fd() always fails to get a valid FD)

为什么BIO_get_fd()总是无法在下面的代码中获得有效的FD?

SSL *pSsl = NULL;

int nRet;
int fdSocket;
fd_set connectionfds;
struct timeval timeout;

BIO_get_ssl(pBio, &pSsl);
if (!pSsl)
    // failed to get SSL pointer of BIO.

SSL_set_mode(pSsl, SSL_MODE_AUTO_RETRY);

BIO_set_conn_hostname(pBio, "HostName");
BIO_set_conn_port(pBio, "PortNumber");

BIO_set_nbio(pBio, 1);

nRet = BIO_do_connect(pBio);

if ((nRet <= 0) && !BIO_should_retry(pBio))
    // failed to establish connection.

if (BIO_get_fd(pBio, &fdSocket) <= 0)
    // failed to get fd but why?

if (nRet <= 0)
{
    FD_ZERO(&connectionfds);
    FD_SET(fdSocket, &connectionfds);

    timeout.tv_usec = 0;
    timeout.tv_sec = 10;

    nRet = select(fdSocket + 1, NULL, &connectionfds, NULL, &timeout);
    if (nRet == 0)
        // timeout has occurred.
}
  • 通过调用BIO * BIO_new_ssl_connect(SSL_CTX * ctx)预先正确创建我的BIO对象
  • 我的OpenSSL版本是v1.0.1e
  • 我在Ubuntu for ARM上进行交叉编译

Why does BIO_get_fd() always fail to get a valid FD in the following piece of code?

SSL *pSsl = NULL;

int nRet;
int fdSocket;
fd_set connectionfds;
struct timeval timeout;

BIO_get_ssl(pBio, &pSsl);
if (!pSsl)
    // failed to get SSL pointer of BIO.

SSL_set_mode(pSsl, SSL_MODE_AUTO_RETRY);

BIO_set_conn_hostname(pBio, "HostName");
BIO_set_conn_port(pBio, "PortNumber");

BIO_set_nbio(pBio, 1);

nRet = BIO_do_connect(pBio);

if ((nRet <= 0) && !BIO_should_retry(pBio))
    // failed to establish connection.

if (BIO_get_fd(pBio, &fdSocket) <= 0)
    // failed to get fd but why?

if (nRet <= 0)
{
    FD_ZERO(&connectionfds);
    FD_SET(fdSocket, &connectionfds);

    timeout.tv_usec = 0;
    timeout.tv_sec = 10;

    nRet = select(fdSocket + 1, NULL, &connectionfds, NULL, &timeout);
    if (nRet == 0)
        // timeout has occurred.
}
  • My BIO object is properly created beforehand by calling BIO *BIO_new_ssl_connect(SSL_CTX *ctx)
  • My OpenSSL version is v1.0.1e
  • I'm cross-compiling on Ubuntu for ARM

原文:https://stackoverflow.com/questions/16652246
更新时间:2023-07-18 12:07

最满意答案

改变这个:

(newh > max - 1) ? newh = 0 : void(null);
        document.location.hash = "#image" + String(newh + 1);

对此:

(newh > max - 1) ? window.location.href = "strategy.html" :
        document.location.hash = "#image" + String(newh + 1);

的jsfiddle


change this:

(newh > max - 1) ? newh = 0 : void(null);
        document.location.hash = "#image" + String(newh + 1);

to this:

(newh > max - 1) ? window.location.href = "strategy.html" :
        document.location.hash = "#image" + String(newh + 1);

jsfiddle

相关问答

更多
  • reset:function(){ if (this.interval) { clearInterval(this.interval); this.interval = false; } this.moveTo($('.slideshow-nav').children().first()); var s ...
  • 这不是幻灯片,它只是一个图像,每次单击一个按钮(调用JavaScript函数)时,您都会随机更改源。 我的建议是使用JavaScript生成1到5之间的随机数。这样的事情: HTML: JavaScript的: function buttonClicked() { var randomNumber = Math.floor((Math.random()*5)+1); document.getElementById("image").src=" ...
  • 您在代码中未使用$ active对象。 如果您删除类.slider_active以及另外一个更正,如果您希望所有浏览器都支持,则setInterval仅适用于mozila 用得像 setInterval(slideSwitch, 5000 ); 只是用 $('.slider_active').removeClass('slider_active'); 你的代码是 function slideSwitch() { var $slider_active = $('div.slider IMG ...
  • 我不是百分之百确定你想要什么,但如果我不得不猜测我会说你可以简单地使用.trigger()来点击任何绑定了点击的元素上的click事件。 $('#nav li a').bind('click', function(){ var numSlide = $(this).attr('rel'); $('.slide-image').html(''); // added the complete ...
  • 相关文章

    更多
  • INSERT INTO blog_appitem (user_id,appid,app_secret,is_valid) VALUES (1, 'wxf415741de036114c','48e1e345fd5f11c93af18ff1714c7f78',1)
  • mysql删除外键(Cannot drop index 'FK7D676EBBD0A6D8FD': needed in a foreign key constraint)
  • 三表连接a,b,c a和b先内连接,再和c外连接,该怎么写
  • Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing
  • Becoming a data scientist
  • 按钮样式
  • a favorite song
  • Solr: a custom Search RequestHandler
  • A Great List of Windows Tools
  • How to Start a Business in 10 Days
  • 最新问答

    更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。