]> granicus.if.org Git - libevent/commitdiff
Do not try to do SSL handshake if the connect() fails
authorAzat Khuzhin <azat@libevent.org>
Wed, 4 Nov 2020 21:57:39 +0000 (00:57 +0300)
committerAzat Khuzhin <azat@libevent.org>
Wed, 4 Nov 2020 21:57:39 +0000 (00:57 +0300)
This will avoid this icky error:

    $ https-client -4 -url https://127.1
    some request failed - no idea which one though!
    error:00000005:lib(0):func(0):DH lib

And instead will report only:

    $ https-client -4 -url https://127.1
    some request failed - no idea which one though!
    socket error = Connection refused (111)

Refs: #1115

bufferevent_ssl.c
util-internal.h

index b34af9af42e75bf8b91139963dae3327b15aa336..a946c162f9d76f166b3230584b8a31a603caedbf 100644 (file)
@@ -739,8 +739,13 @@ be_ssl_handshakeeventcb(evutil_socket_t fd, short what, void *ptr)
        bufferevent_incref_and_lock_(&bev_ssl->bev.bev);
        if (what & EV_TIMEOUT) {
                bufferevent_run_eventcb_(&bev_ssl->bev.bev, BEV_EVENT_TIMEOUT, 0);
-       } else
-               do_handshake(bev_ssl);/* XXX handle failure */
+       } else {
+               int c = evutil_socket_finished_connecting_(fd);
+               if (c < 0)
+                       bufferevent_run_eventcb_(&bev_ssl->bev.bev, BEV_EVENT_ERROR, 0);
+               else
+                       do_handshake(bev_ssl);/* XXX handle failure */
+       }
        bufferevent_decref_and_unlock_(&bev_ssl->bev.bev);
 }
 
index 9010b2e375432c6d4342d1d1c79953b6a6f37b3d..dabb6d6ba0119ecc9f40073a9ec00f24daae3c17 100644 (file)
@@ -300,6 +300,7 @@ int evutil_read_file_(const char *filename, char **content_out, size_t *len_out,
 EVENT2_EXPORT_SYMBOL
 int evutil_socket_connect_(evutil_socket_t *fd_ptr, const struct sockaddr *sa, int socklen);
 
+EVENT2_EXPORT_SYMBOL
 int evutil_socket_finished_connecting_(evutil_socket_t fd);
 
 #ifdef EVENT__HAVE_AFUNIX_H