Browse Source

fix Windows warnings: getpid, htole64, gettimeofday, socket_t mismatches, radix min

topo_upd
Evgeny 2 months ago
parent
commit
b1bf27d023
  1. 3
      lib/platform_compat.h
  2. 3
      lib/radix.c
  3. 2
      src/transport_layer/dummynet.c
  4. 3
      src/transport_layer/dummynet.h
  5. 2
      tests/bbr_integration/test_bbr_integration.c
  6. 2
      tests/test_udp_proxy.c

3
lib/platform_compat.h

@ -28,6 +28,8 @@ extern "C" {
#define be32toh(x) _byteswap_ulong(x)
#define htobe64(x) _byteswap_uint64(x)
#define be64toh(x) _byteswap_uint64(x)
#define htole64(x) (x)
#define le64toh(x) (x)
#else
#include <endian.h>
#endif
@ -35,6 +37,7 @@ extern "C" {
// POSIX functions missing on Windows
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define getpid() ((int)GetCurrentProcessId())
// memmem — not available on Windows
#define memmem compat_memmem

3
lib/radix.c

@ -38,7 +38,8 @@
#include "debug_config.h"
#include "radix.h"
#define min(a, b) ((a) < (b) ? (a) : (b))
#undef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
static struct radix_node
*rn_insert(void *, struct radix_head *, int *,

2
src/transport_layer/dummynet.c

@ -528,7 +528,7 @@ void dummynet_reset_stats(struct dummynet* dn, int direction) {
}
/* Возвращает файловый дескриптор сокета */
int dummynet_get_socket(struct dummynet* dn) {
socket_t dummynet_get_socket(struct dummynet* dn) {
if (!dn) return SOCKET_INVALID;
return dn->sock;
}

3
src/transport_layer/dummynet.h

@ -28,6 +28,7 @@ extern "C" {
#include <stdint.h>
#include <stddef.h>
#include "../lib/socket_compat.h"
// Forward declarations
struct UASYNC;
@ -127,7 +128,7 @@ void dummynet_reset_stats(struct dummynet* dn, int direction);
* @param dn Контекст dummynet
* @return socket_t или SOCKET_INVALID
*/
int dummynet_get_socket(struct dummynet* dn);
socket_t dummynet_get_socket(struct dummynet* dn);
/**
* @brief Возвращает listen_port

2
tests/bbr_integration/test_bbr_integration.c

@ -101,7 +101,7 @@ struct test_ctx {
/* ===== Time helper ===== */
static uint64_t now_us(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
utun_gettimeofday(&tv, NULL);
return (uint64_t)tv.tv_sec * 1000000ULL + tv.tv_usec;
}

2
tests/test_udp_proxy.c

@ -173,7 +173,7 @@ int main(void) {
struct sockaddr_in ea = {.sin_family = AF_INET, .sin_addr = {.s_addr = inet_addr("127.0.0.1")}, .sin_port = htons(UDP_ECHO_PORT)};
if (bind(g_echo_sock, (struct sockaddr*)&ea, sizeof(ea)) < 0) { printf("[FAIL] echo bind: %s\n", strerror(errno)); goto done; }
socket_set_nonblocking(g_echo_sock);
g_echo_id = uasync_add_socket(ua, g_echo_sock, udp_echo_cb, NULL, NULL, NULL);
g_echo_id = uasync_add_socket_t(ua, g_echo_sock, udp_echo_cb, NULL, NULL, NULL);
g_to_id = uasync_set_timeout(ua, 100, NULL, monitor, "mon");
void* to_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS * 10, NULL, test_timeout, "to");

Loading…
Cancel
Save