network: fix regression on socket errno handling
@@ -226,6 +226,7 @@ static int net_connect_sync(int fd, const struct sockaddr *addr, socklen_t addrl
{
int ret;
int err;
+ int socket_errno;
fd_set wait_set;
struct timeval timeout;
@@ -240,8 +241,9 @@ static int net_connect_sync(int fd, const struct sockaddr *addr, socklen_t addrl
* socket status, getting a EINPROGRESS is expected, but any other case
* means a failure.
*/
+ socket_errno = errno;
err = flb_socket_error(fd);
- if (!FLB_EINPROGRESS(err)) {
+ if (!FLB_EINPROGRESS(socket_errno) && err != 0) {
flb_error("[net] connection #%i failed to: %s:%i",
fd, host, port);
goto exit_error;
@@ -306,6 +308,7 @@ static int net_connect_async(int fd,
int ret;
int err;
int error = 0;
+ int socket_errno;
uint32_t mask;
char so_error_buf[256];
char *str;
@@ -322,8 +325,9 @@ static int net_connect_async(int fd,
* socket status, getting a EINPROGRESS is expected, but any other case
* means a failure.
*/
+ socket_errno = errno;
err = flb_socket_error(fd);
- if (!FLB_EINPROGRESS(err) && err != 0) {
+ if (!FLB_EINPROGRESS(socket_errno) && err != 0) {
flb_error("[net] connection #%i failed to: %s:%i",
fd, host, port);
return -1;
