aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2022-07-22 19:48:00 -0700
committerTrumeet <yuuta@yuuta.moe>2022-07-22 19:48:00 -0700
commit78d23828d7024a827135eb824e77e7bbf63bc065 (patch)
treed126f6757c4677a9b83b1ecb0022fb2f8ac14553
parentf5327ba5cac39df2072b5a3fed0f84acb6408138 (diff)
downloadacron-78d23828d7024a827135eb824e77e7bbf63bc065.tar
acron-78d23828d7024a827135eb824e77e7bbf63bc065.tar.gz
acron-78d23828d7024a827135eb824e77e7bbf63bc065.tar.bz2
acron-78d23828d7024a827135eb824e77e7bbf63bc065.zip
fix(libacron): use WSAGetLastError() instead of errno for WinSock error codes
WinSock does not use errno. Signed-off-by: Trumeet <yuuta@yuuta.moe>
-rw-r--r--client/libacron/net.c16
1 files changed, 6 insertions, 10 deletions
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 <winsock2.h>
#include <ws2tcpip.h>
+#define errno_sock WSAGetLastError()
#else
+#define errno_sock errno
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
@@ -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;