int sfd = socket(AF_INET6, SOCK_STREAM, 0);
if (sfd < 0) continue;
struct timeval timeout;
timeout.tv_sec = 60;
timeout.tv_usec = 0;
setsockopt(sfd, SOL_SOCKET, SO_RCVTIMEO, (char *) &timeout, sizeof(timeout));
setsockopt(sfd, SOL_SOCKET, SO_SNDTIMEO, (char *) &timeout, sizeof(timeout));
if (connect(sfd, (struct sockaddr*) &ig, sizeof(struct sockaddr_in6))) {
close(sfd);
continue;
}
SSL* ssl = SSL_new(ctx);
if (ssl == NULL) {
close(sfd);
continue;
}
SSL_set_connect_state(ssl);
SSL_set_fd(ssl, sfd);
printf("%i\n", SSL_get_fd(ssl));
int con = SSL_connect(ssl);
OpenSSL 导致在我调用 SSL_connect 的行上触发 SIGPIPE。我运行了 GDB 并确保套接字没有关闭。在 /proc/fd/# 中,套接字在之前或之后都没有显示为关闭。我尝试切换 set_fd 和 connect_state 调用的顺序。我想我把 OpenSSL 搞砸了,但我似乎无法弄清楚。