From 78d23828d7024a827135eb824e77e7bbf63bc065 Mon Sep 17 00:00:00 2001 From: Trumeet Date: Fri, 22 Jul 2022 19:48:00 -0700 Subject: fix(libacron): use WSAGetLastError() instead of errno for WinSock error codes WinSock does not use errno. Signed-off-by: Trumeet --- client/libacron/net.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'client/libacron/net.c') diff --git a/client/libacron/net.c b/client/libacron/net.c index aeff5e8..7ac3bda 100644 --- a/client/libacron/net.c +++ b/client/libacron/net.c @@ -23,7 +23,9 @@ #ifdef WIN32 #include #include +#define errno_sock WSAGetLastError() #else +#define errno_sock errno #include #include #include @@ -57,7 +59,7 @@ static void on_send_handler(struct wic_inst *inst, retval = (int) send(conn->fd, &ptr[pos], (int) n, 0); if (retval <= 0) { /* There's no way to abort the process. */ - int e = errno; + int e = errno_sock; LOGEV("Cannot write to socket: %s (%d).", strerror2(errno), e); @@ -228,7 +230,7 @@ int ac_connect(ac_connection_parameters_t parameters, void **out) { SOCKET fd; if ((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) <= 0) { - const int e = errno; + const int e = errno_sock; LOGEV("Cannot create socket: %s (%d).", strerror2(e), e); @@ -237,16 +239,10 @@ int ac_connect(ac_connection_parameters_t parameters, void **out) { return AC_E_NET; } if (connect(fd, res->ai_addr, res->ai_addrlen) < 0) { -#ifdef WIN32 - const int e = WSAGetLastError(); - LOGEV("Cannot connect to socket: %d.", - e); -#else - const int e = errno; + const int e = errno_sock; LOGEV("Cannot connect to socket: %s (%d).", strerror2(e), e); -#endif closesocket(fd); freeaddrinfo(res); conn_free(conn); @@ -305,7 +301,7 @@ int ac_receive(void *connection, ac_obj_t **response) { if ((bytes = (int) recv(conn->fd, buffer, sizeof(buffer), 0)) <= 0) { LOGDV("recv(%d) = %d", conn->fd, bytes); if (bytes < 0) { - const int e = errno; + const int e = errno_sock; if (e == EAGAIN) { /* Timeout */ *response = NULL; -- cgit v1.2.3