Skip to content

Display and control your Android device

Simplify net.c

Romain Vimontdb6252e52b95
diff --git a/app/meson.build b/app/meson.build
index 3bcb9bc1..62006ca1 100644
--- a/app/meson.build
+++ b/app/meson.build
@@ -76,11 +76,9 @@ cc = meson.get_compiler('c')
if host_machine.system() == 'windows'
src += [ 'src/sys/win/command.c' ]
- src += [ 'src/sys/win/net.c' ]
dependencies += cc.find_library('ws2_32')
else
src += [ 'src/sys/unix/command.c' ]
- src += [ 'src/sys/unix/net.c' ]
endif
conf = configuration_data()
diff --git a/app/src/sys/unix/net.c b/app/src/sys/unix/net.c
deleted file mode 100644
index d67a660f..00000000
--- a/app/src/sys/unix/net.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "util/net.h"
-
-#include <unistd.h>
-
-#include "config.h"
-
-bool
-net_init(void) {
- // do nothing
- return true;
-}
-
-void
-net_cleanup(void) {
- // do nothing
-}
-
-bool
-net_close(socket_t socket) {
- return !close(socket);
-}
diff --git a/app/src/sys/win/net.c b/app/src/sys/win/net.c
deleted file mode 100644
index aebce7fc..00000000
--- a/app/src/sys/win/net.c
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "util/net.h"
-
-#include "config.h"
-#include "util/log.h"
-
-bool
-net_init(void) {
- WSADATA wsa;
- int res = WSAStartup(MAKEWORD(2, 2), &wsa) < 0;
- if (res < 0) {
- LOGC("WSAStartup failed with error %d", res);
- return false;
- }
- return true;
-}
-
-void
-net_cleanup(void) {
- WSACleanup();
-}
-
-bool
-net_close(socket_t socket) {
- return !closesocket(socket);
-}
diff --git a/app/src/util/net.c b/app/src/util/net.c
index bf4389dd..efce6fa9 100644
--- a/app/src/util/net.c
+++ b/app/src/util/net.c
@@ -1,6 +1,7 @@
#include "net.h"
#include <stdio.h>
+#include <SDL2/SDL_platform.h>
#include "config.h"
#include "log.h"
@@ -115,3 +116,32 @@ bool
net_shutdown(socket_t socket, int how) {
return !shutdown(socket, how);
}
+
+bool
+net_init(void) {
+#ifdef __WINDOWS__
+ WSADATA wsa;
+ int res = WSAStartup(MAKEWORD(2, 2), &wsa) < 0;
+ if (res < 0) {
+ LOGC("WSAStartup failed with error %d", res);
+ return false;
+ }
+#endif
+ return true;
+}
+
+void
+net_cleanup(void) {
+#ifdef __WINDOWS__
+ WSACleanup();
+#endif
+}
+
+bool
+net_close(socket_t socket) {
+#ifdef __WINDOWS__
+ return !closesocket(socket);
+#else
+ return !close(socket);
+#endif
+}