From 26c07567cce84277d024317d7c0caff78b335fce Mon Sep 17 00:00:00 2001 From: kdx Date: Wed, 30 Aug 2023 05:47:28 +0200 Subject: ping every frame --- inc/netcode.h | 2 ++ src/main.c | 5 +++++ src/netcode.c | 9 +++++++++ 3 files changed, 16 insertions(+) diff --git a/inc/netcode.h b/inc/netcode.h index ac1bb18..148a519 100644 --- a/inc/netcode.h +++ b/inc/netcode.h @@ -8,3 +8,5 @@ void netcode_deinit(void); int netcode_send(void *data, size_t size); int netcode_recv(void *data, size_t size); + +int netcode_ping(void); diff --git a/src/main.c b/src/main.c index 68080b6..b56f427 100644 --- a/src/main.c +++ b/src/main.c @@ -51,5 +51,10 @@ main_loop(void *udata) TZR_DrawBegin(); TZR_DrawEnd(); + if (netcode_ping()) { + log_error("netcode_ping failed"); + return -1; + } + return 0; } diff --git a/src/netcode.c b/src/netcode.c index b3ac6c3..5ae5990 100644 --- a/src/netcode.c +++ b/src/netcode.c @@ -99,3 +99,12 @@ netcode_recv(void *data, size_t size) } return 0; } + +int +netcode_ping(void) +{ + char a = 0; + if (_sock_host != NULL) + return netcode_recv(&a, 1); + return netcode_send(&a, 1); +} -- cgit v1.2.3