Fix auto-reconnect when domain name resolution fails

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
Jianhui Zhao
2025-10-22 19:04:26 +08:00
parent 226a7dd76e
commit c514633b0d
2 changed files with 8 additions and 5 deletions

View File

@@ -187,11 +187,11 @@ int tcp_connect(struct ev_loop *loop, const char *host, int port,
if (ret) {
if (ret == EAI_SYSTEM) {
log_err("getaddrinfo failed: %s\n", strerror(errno));
return -1;
goto fail;
}
log_err("getaddrinfo failed: %s\n", gai_strerror(ret));
return -1;
goto fail;
}
for (rp = result; rp != NULL; rp = rp->ai_next) {
@@ -211,5 +211,8 @@ int tcp_connect(struct ev_loop *loop, const char *host, int port,
free_addrinfo:
freeaddrinfo(result);
fail:
if (sock < 0)
on_connected(-1, arg);
return sock;
}

View File

@@ -772,13 +772,13 @@ int rtty_start(struct rtty *rtty)
ev_init(&rtty->tmr, rtty_timer_cb);
INIT_LIST_HEAD(&rtty->ttys);
INIT_LIST_HEAD(&rtty->http_conns);
if (tcp_connect(rtty->loop, rtty->host, rtty->port, on_net_connected, rtty) < 0
&& !rtty->reconnect)
return -1;
INIT_LIST_HEAD(&rtty->ttys);
INIT_LIST_HEAD(&rtty->http_conns);
return 0;
}