| 551 | } |
| 552 | |
| 553 | Result Dial(HPool pool, const char* host, uint16_t port, bool ssl, int timeout, int* cancelflag, HConnection* connection, dmSocket::Result* sock_res) |
| 554 | { |
| 555 | // try connecting to the host using ipv4 first |
| 556 | bool ipv4 = true; |
| 557 | bool ipv6 = false; |
| 558 | uint64_t dial_started = dmTime::GetMonotonicTime(); |
| 559 | Result r = DoDial(pool, host, port, ssl, timeout, cancelflag, connection, sock_res, ipv4, ipv6); |
| 560 | // Only if handshake failed NOT because of timeout |
| 561 | if (r == RESULT_OK || r == RESULT_SHUT_DOWN || r == RESULT_OUT_OF_RESOURCES || |
| 562 | (r == RESULT_HANDSHAKE_FAILED && *sock_res != dmSocket::RESULT_WOULDBLOCK)) |
| 563 | { |
| 564 | return r; |
| 565 | } |
| 566 | // ipv4 connection failed - reduce timeout (if needed) and try using ipv6 instead |
| 567 | ipv4 = false; |
| 568 | ipv6 = true; |
| 569 | if (timeout > 0) |
| 570 | { |
| 571 | timeout = timeout - (int)(dmTime::GetMonotonicTime() - dial_started); |
| 572 | if (timeout <= 0) |
| 573 | { |
| 574 | return RESULT_SOCKET_ERROR; |
| 575 | } |
| 576 | } |
| 577 | return DoDial(pool, host, port, ssl, timeout, cancelflag, connection, sock_res, ipv4, ipv6); |
| 578 | } |
| 579 | |
| 580 | Result Dial(HPool pool, const char* host, uint16_t port, bool ssl, int timeout, HConnection* connection, dmSocket::Result* sock_res) |
| 581 | { |