我正在使用 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
来关闭连接,哦,程序收到信号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);
有谁知道为什么吗?
提前致谢
最佳答案
如果 SSL_read 出现 I/O 错误,则调用 SSL_shutdown 没有多大意义,因为关闭会尝试向对等方发送“关闭通知”关闭警报,而这显然不适用于断开的连接。因此,您会得到 SIGPIPE 或 EPIPE。在这种情况下,从 SSL_read 获取 ECONNRESET 可能意味着客户端已硬关闭连接,例如不做 SSL_shutdown。错误发生后,您不应继续使用套接字,例如甚至不执行 SSL_shutdown。
关于c++ - OpenSSL SSL_shutdown 收到信号 SIGPIPE,Broken pipe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22590055/