Simplify net.c
The platform-specific code for net.c was implemented in sys/*/net.c. But the differences are quite limited, so use ifdef-blocks in the single net.c instead.
This commit is contained in:
parent
229eeb24a2
commit
db6252e52b
4 changed files with 30 additions and 48 deletions
|
@ -76,11 +76,9 @@ cc = meson.get_compiler('c')
|
||||||
|
|
||||||
if host_machine.system() == 'windows'
|
if host_machine.system() == 'windows'
|
||||||
src += [ 'src/sys/win/command.c' ]
|
src += [ 'src/sys/win/command.c' ]
|
||||||
src += [ 'src/sys/win/net.c' ]
|
|
||||||
dependencies += cc.find_library('ws2_32')
|
dependencies += cc.find_library('ws2_32')
|
||||||
else
|
else
|
||||||
src += [ 'src/sys/unix/command.c' ]
|
src += [ 'src/sys/unix/command.c' ]
|
||||||
src += [ 'src/sys/unix/net.c' ]
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
conf = configuration_data()
|
conf = configuration_data()
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <SDL2/SDL_platform.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
@ -115,3 +116,32 @@ bool
|
||||||
net_shutdown(socket_t socket, int how) {
|
net_shutdown(socket_t socket, int how) {
|
||||||
return !shutdown(socket, 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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue