我正在使用openssl-0.9.8e编写一个http/https客户端
调用SSL_read()
时出现错误
然后,我调用SSL_get_error
get SSL_ERROR_SYSCALL
和errno ECONNRESET 104 /* Connection reset by peer */
根据SSL文档,这是它的意思:
SSL_ERROR_SYSCALL
Some I/O error occurred. The OpenSSL error queue may contain more information on the error.
If the error queue is empty (i.e. ERR_get_error() returns 0), ret can be used to find out more about the
error: If ret == 0, an EOF was observed that violates the protocol. If ret == -1, the underlying BIO
reported an I/O error (for socket I/O on Unix systems, consult errno for details).
好的,连接重置,我调用SSL_shutdown
关闭连接,哦,Program received signal SIGPIPE, Broken pipe.
天啊,我调用signal(SIGPIPE, SIG_IGN);
忽略"SIGPIPE“信号,但它似乎不起作用~
分段故障发生
#0 0x00000032bd00d96b in write () from /lib64/libpthread.so.0
#1 0x0000003add478367 in ?? () from /lib64/libcrypto.so.6
#2 0x0000003add4766fe in BIO_write () from /lib64/libcrypto.so.6
#3 0x0000003add8208fd in ssl3_write_pending () from /lib64/libssl.so.6
#4 0x0000003add820d9a in ssl3_dispatch_alert () from /lib64/libssl.so.6
#5 0x0000003add81e982 in ssl3_shutdown () from /lib64/libssl.so.6
#6 0x00000000004565d0 in CWsPollUrl::SSLClear (this=<value optimized out>, ctx=0x2aaab804a1b0, ssl=0x2aaab804a680)
at ../src/Wspoll.cpp:1122
#7 0x00000000004575e0 in CWsPollUrl::asyncEventDelete (this=0x4d422e50, eev=0x2aaab8001160) at ../src/Wspoll.cpp:1546
#8 0x000000000045928a in CWsPollUrl::onFail (this=0x4d422e50, eev=0x2aaab8001160, errorCode=4) at ../src/Wspoll.cpp:1523
#9 0x000000000045ab17 in CWsPollUrl::handleData (this=0x4d422e50, eev=0x2aaab8001160, len=<value optimized out>) at ../src/Wspoll.cpp:1259
#10 0x000000000045abcc in CWsPollUrl::asyncRecvEvent (this=0x4d422e50, fd=<value optimized out>, eev=0x2aaab8001160)
at ../src/Wspoll.cpp:1211
#11 0x00000000004636b5 in event_base_loop (base=0x14768360, flags=0) at event.c:1350
#12 0x0000000000456a62 in CWsPollUrl::run (this=<value optimized out>, param=<value optimized out>) at ../src/Wspoll.cpp:461
#13 0x0000000000436c5c in doPollUrl (data=<value optimized out>, user_data=<value optimized out>) at ../src/PollStrategy.cpp:151
#14 0x00000032bf44a95d in ?? () from /lib64/libglib-2.0.so.0
#15 0x00000032bf448e04 in ?? () from /lib64/libglib-2.0.so.0
#16 0x00000032bd00677d in start_thread () from /lib64/libpthread.so.0
#17 0x00000032bc4d3c1d in clone () from /lib64/libc.so.6
为什么我得到了SIGPIPE信号,我已经调用了signal(SIGPIPE, SIG_IGN);
有人知道为什么吗?
提前感谢
发布于 2014-03-23 11:50:44
如果SSL_read出现I/O错误,调用SSL_shutdown没有多大意义,因为shutdown会尝试向对等设备发送"close notify“关闭警报,而这显然不会在断开的连接上起作用。因此,您将获得SIGPIPE或EPIPE。在这种情况下,从SSL_read获取ECONNRESET可能意味着客户端已经硬地关闭了连接,例如,没有执行SSL_shutdown。错误发生后,您不应继续使用套接字,例如,甚至不应执行SSL_shutdown。
发布于 2021-09-15 08:10:41
除了@SteffenUllrich回答之外,您还可以在调用SSL_shutdown
之前调用SSL_get_shutdown
,并检查是否已经设置了SSL_SENT_SHUTDOWN
标志。你可以这样做:
//Perform a mutex lock here
if(SSL_get_shutdown(ssl) & SSL_SENT_SHUTDOWN)
{
printf("shutdown request ignored\n");
}
else
{
SSL_shutdown(con->tls.openssl);
}
//Perform a mutex unlock here
在多个线程共享SSL *
指针的多线程程序中,SSL_shutdown
可能已被另一个线程调用,此代码可以保护您免受SIGPIPE
信号的影响。
https://stackoverflow.com/questions/22590055
复制