Improve logging on failed connect attempt

This commit is contained in:
matt335672
2025-03-08 10:45:24 +00:00
parent 39ec7089ac
commit 39a178902e
4 changed files with 73 additions and 55 deletions
+7
View File
@@ -22,6 +22,8 @@
#include <config_ac.h>
#endif
#include <errno.h>
#include "os_calls.h"
#include "string_calls.h"
#include "trans.h"
@@ -750,6 +752,7 @@ trans_connect(struct trans *self, const char *server, const char *port,
unsigned int start_time = g_get_elapsed_ms();
int error;
int ms_before_next_connect;
int connect_errno = 0;
/*
* Function pointers which we use in the main loop to avoid
@@ -792,6 +795,7 @@ trans_connect(struct trans *self, const char *server, const char *port,
if (self->sck < 0)
{
connect_errno = errno;
error = 1;
break;
}
@@ -800,6 +804,7 @@ trans_connect(struct trans *self, const char *server, const char *port,
g_file_set_cloexec(self->sck, 1);
g_tcp_set_non_blocking(self->sck);
error = f_connect(self->sck, server, port);
connect_errno = errno;
if (error == 0)
{
/* Connect was immediately successful */
@@ -851,6 +856,8 @@ trans_connect(struct trans *self, const char *server, const char *port,
g_tcp_close(self->sck);
self->sck = -1;
}
/* Ensure errno is representative of the last connection attempt */
errno = connect_errno;
self->status = TRANS_STATUS_DOWN;
}
else
+3
View File
@@ -158,6 +158,9 @@ trans_write_copy_s(struct trans *self, struct stream *out_s);
*
* Multiple connection attempts may be made within the timeout period.
*
* If the operation is not successful, errno will have been set by
* the last connection attempt.
*
* If the operation is successful, 0 is returned and self->status will
* be TRANS_STATUS_UP
*/
+9 -2
View File
@@ -1732,8 +1732,16 @@ lib_mod_connect(struct vnc *v)
error = trans_connect(v->trans, v->ip, con_port, 3000);
if (error == 0)
if (error != 0)
{
g_snprintf(text, sizeof(text), "Error connecting to VNC server [%s]",
g_get_strerror());
v->server_msg(v, text, 0);
free_stream(s);
free_stream(pixel_format);
return 1;
}
v->server_msg(v, "VNC tcp connected", 0);
/* protocol version */
init_stream(s, 8192);
@@ -1798,7 +1806,6 @@ lib_mod_connect(struct vnc *v)
error = 1;
}
}
}
if (error != 0)
{
+2 -1
View File
@@ -324,7 +324,8 @@ lib_mod_connect(struct mod *mod)
}
else
{
mod->server_msg(mod, "connection problem, giving up", 0);
LOG(LOG_LEVEL_ERROR, "Error connecting to X server [%s]",
g_get_strerror());
}
if (error == 0)