@@ -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,17 @@ 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) {
3376
+ break ;
3377
+ }
3372
3378
}
3373
3379
3374
3380
freeaddrinfo (result);
@@ -3469,7 +3475,7 @@ inline socket_t create_client_socket(
3469
3475
time_t write_timeout_usec, const std::string &intf, Error &error) {
3470
3476
auto sock = create_socket (
3471
3477
host, ip, port, address_family, 0 , tcp_nodelay, std::move (socket_options),
3472
- [&](socket_t sock2, struct addrinfo &ai) -> bool {
3478
+ [&](socket_t sock2, struct addrinfo &ai, bool & quit ) -> bool {
3473
3479
if (!intf.empty ()) {
3474
3480
#ifdef USE_IF2IP
3475
3481
auto ip_from_if = if2ip (address_family, intf);
@@ -3493,7 +3499,12 @@ inline socket_t create_client_socket(
3493
3499
}
3494
3500
error = wait_until_socket_is_ready (sock2, connection_timeout_sec,
3495
3501
connection_timeout_usec);
3496
- if (error != Error::Success) { return false ; }
3502
+ if (error != Error::Success) {
3503
+ if (error == Error::ConnectionTimeout) {
3504
+ quit = true ;
3505
+ }
3506
+ return false ;
3507
+ }
3497
3508
}
3498
3509
3499
3510
set_nonblocking (sock2, false );
@@ -6470,7 +6481,7 @@ Server::create_server_socket(const std::string &host, int port,
6470
6481
return detail::create_socket (
6471
6482
host, std::string (), port, address_family_, socket_flags, tcp_nodelay_,
6472
6483
std::move (socket_options),
6473
- [](socket_t sock, struct addrinfo &ai) -> bool {
6484
+ [](socket_t sock, struct addrinfo &ai, bool & quit ) -> bool {
6474
6485
if (::bind (sock, ai.ai_addr , static_cast <socklen_t >(ai.ai_addrlen ))) {
6475
6486
return false ;
6476
6487
}
0 commit comments