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
*/