@@ -3278,7 +3278,8 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
3278
3278
3279
3279
if (socket_options) { socket_options (sock); }
3280
3280
3281
- if (!bind_or_connect (sock, hints)) {
3281
+ bool dummy;
3282
+ if (!bind_or_connect (sock, hints, dummy)) {
3282
3283
close_socket (sock);
3283
3284
sock = INVALID_SOCKET;
3284
3285
}
@@ -3363,12 +3364,15 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
3363
3364
}
3364
3365
3365
3366
// bind or connect
3366
- if (bind_or_connect (sock, *rp)) {
3367
+ auto quit = false ;
3368
+ if (bind_or_connect (sock, *rp, quit)) {
3367
3369
freeaddrinfo (result);
3368
3370
return sock;
3369
3371
}
3370
3372
3371
3373
close_socket (sock);
3374
+
3375
+ if (quit) { break ; }
3372
3376
}
3373
3377
3374
3378
freeaddrinfo (result);
@@ -3469,7 +3473,7 @@ inline socket_t create_client_socket(
3469
3473
time_t write_timeout_usec, const std::string &intf, Error &error) {
3470
3474
auto sock = create_socket (
3471
3475
host, ip, port, address_family, 0 , tcp_nodelay, std::move (socket_options),
3472
- [&](socket_t sock2, struct addrinfo &ai) -> bool {
3476
+ [&](socket_t sock2, struct addrinfo &ai, bool &quit ) -> bool {
3473
3477
if (!intf.empty ()) {
3474
3478
#ifdef USE_IF2IP
3475
3479
auto ip_from_if = if2ip (address_family, intf);
@@ -3493,7 +3497,10 @@ inline socket_t create_client_socket(
3493
3497
}
3494
3498
error = wait_until_socket_is_ready (sock2, connection_timeout_sec,
3495
3499
connection_timeout_usec);
3496
- if (error != Error::Success) { return false ; }
3500
+ if (error != Error::Success) {
3501
+ if (error == Error::ConnectionTimeout) { quit = true ; }
3502
+ return false ;
3503
+ }
3497
3504
}
3498
3505
3499
3506
set_nonblocking (sock2, false );
@@ -6470,7 +6477,7 @@ Server::create_server_socket(const std::string &host, int port,
6470
6477
return detail::create_socket (
6471
6478
host, std::string (), port, address_family_, socket_flags, tcp_nodelay_,
6472
6479
std::move (socket_options),
6473
- [](socket_t sock, struct addrinfo &ai) -> bool {
6480
+ [](socket_t sock, struct addrinfo &ai, bool & /* quit */ ) -> bool {
6474
6481
if (::bind (sock, ai.ai_addr , static_cast <socklen_t >(ai.ai_addrlen ))) {
6475
6482
return false ;
6476
6483
}
0 commit comments