fix(test): build NAT/multipath rebind tests under MSVC

The issue #188 NAT/socket-rebind and multipath cname integration
tests included <pthread.h> and initialised their tracker mutex with
PTHREAD_MUTEX_INITIALIZER.  MSVC has no system pthread.h, and the
Windows pthread-shim maps pthread_mutex_t to a CRITICAL_SECTION,
which cannot be initialised statically, so the whole librist VS
solution failed to build (only these tests; the library and tools
were fine).

Follow the convention already used by test_send_receive.c and
test_reflector.c: include "pthread-shim.h" (directly, or via
rist-private.h), initialise the tracker mutex at runtime with
pthread_mutex_init(), and declare the feeder threads with the
PTHREAD_START_FUNC() macro so they match the shim's __stdcall/LPVOID
signature.  POSIX builds are unchanged; the suite now also compiles
under MSVC.
This commit is contained in:
Sergio Ammirata
2026-06-21 21:31:06 -04:00
parent 2863e43834
commit d8d9034777
6 changed files with 36 additions and 16 deletions
+4
View File
@@ -219,6 +219,10 @@ CI / Test Coverage:
against the 2048-bit RFC 5054 group. Added four end-to-end tests
covering both PAD and legacy modes plus the two cross-mode failure
cases.
- The issue #188 NAT/socket-rebind and multipath cname integration
tests now compile under MSVC: they use the Windows pthread-shim
(runtime mutex initialisation and PTHREAD_START_FUNC thread entry
points) instead of a direct <pthread.h> dependency.
Tools:
- ristsender: new --blind-send option. Decouples the sender from
+4 -2
View File
@@ -37,7 +37,6 @@
#include "librist/librist.h"
#include "rist-private.h"
#include <inttypes.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -45,6 +44,8 @@
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
static struct rist_logging_settings *log_settings = NULL;
@@ -54,7 +55,7 @@ static struct {
bool second_seen;
struct rist_peer *second_peer;
} cb_state;
static pthread_mutex_t cb_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t cb_lock;
static int log_cb(void *arg, enum rist_log_level level, const char *msg) {
(void)arg;
@@ -118,6 +119,7 @@ int main(int argc, char *argv[]) {
const char *crypto_suffix = use_psk ? "&secret=testkey1234&aes-type=128" : "";
const int listen_port = use_psk ? 22001 : 22000;
memset(&cb_state, 0, sizeof(cb_state));
pthread_mutex_init(&cb_lock, NULL);
if (rist_logging_set(&log_settings, RIST_LOG_INFO, log_cb,
NULL, NULL, stderr) != 0) {
+10 -4
View File
@@ -47,12 +47,17 @@
#include "librist/librist_srp.h"
#include "rist-private.h"
#include <inttypes.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
#define CNAME "bonded-1"
#define PSK "sharedgroupkey9090"
#define SRP_USER "bondeduser"
@@ -60,7 +65,7 @@
static struct rist_logging_settings *log_settings = NULL;
static pthread_mutex_t tracker_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t tracker_lock;
#define MAX_TRACKED_PEERS 16
static struct {
struct rist_peer *seen[MAX_TRACKED_PEERS];
@@ -104,7 +109,7 @@ static int rx_data_cb(void *arg, struct rist_data_block *b) {
return 0;
}
static void *sender_feed(void *arg) {
static PTHREAD_START_FUNC(sender_feed, arg) {
struct rist_ctx *tx = arg;
uint32_t counter = 0;
while (sender_run) {
@@ -117,7 +122,7 @@ static void *sender_feed(void *arg) {
counter++;
usleep(20000); /* ~50 pkt/s */
}
return NULL;
return 0;
}
static struct rist_peer *add_path(struct rist_ctx *rx, int listen_port,
@@ -150,6 +155,7 @@ int main(int argc, char *argv[]) {
if (rist_logging_set(&log_settings, RIST_LOG_INFO, log_cb, NULL, NULL, stderr) != 0)
return 99;
memset(&tracker, 0, sizeof(tracker));
pthread_mutex_init(&tracker_lock, NULL);
fprintf(stderr, "== mode: %s ==\n", use_srp ? "SRP (same user/pass on both paths)"
: "shared PSK");
+10 -4
View File
@@ -40,12 +40,17 @@
#include "librist/librist_srp.h"
#include "rist-private.h"
#include <inttypes.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
#define LISTEN_PORT 19956
#define LEG_A_PORT 20081
#define LEG_B_PORT 20082
@@ -56,7 +61,7 @@
static struct rist_logging_settings *log_settings = NULL;
static pthread_mutex_t tracker_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t tracker_lock;
#define MAX_TRACKED_PEERS 16
static struct {
struct rist_peer *seen[MAX_TRACKED_PEERS];
@@ -100,7 +105,7 @@ static int rx_data_cb(void *arg, struct rist_data_block *b) {
return 0;
}
static void *sender_feed(void *arg) {
static PTHREAD_START_FUNC(sender_feed, arg) {
struct rist_ctx *tx = arg;
uint32_t counter = 0;
while (sender_run) {
@@ -113,7 +118,7 @@ static void *sender_feed(void *arg) {
counter++;
usleep(20000); /* ~50 pkt/s */
}
return NULL;
return 0;
}
static struct rist_peer *add_srp_leg(struct rist_ctx *rx, int local_port) {
@@ -139,6 +144,7 @@ int main(void) {
if (rist_logging_set(&log_settings, RIST_LOG_INFO, log_cb, NULL, NULL, stderr) != 0)
return 99;
memset(&tracker, 0, sizeof(tracker));
pthread_mutex_init(&tracker_lock, NULL);
/* sender: listener, MAIN, single-user SRP authenticator, streams. */
struct rist_ctx *tx = NULL;
+3 -2
View File
@@ -54,7 +54,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <pthread.h>
#include "pthread-shim.h"
#ifdef _WIN32
#include <windows.h>
@@ -76,7 +76,7 @@ static struct {
struct rist_peer *seen[MAX_TRACKED_PEERS];
int count;
} tracker;
static pthread_mutex_t tracker_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t tracker_lock;
static int log_cb(void *arg, enum rist_log_level level, const char *msg) {
(void)arg;
@@ -153,6 +153,7 @@ int main(int argc, char *argv[]) {
listen_port, crypto_suffix);
memset(&tracker, 0, sizeof(tracker));
pthread_mutex_init(&tracker_lock, NULL);
if (rist_logging_set(&log_settings, RIST_LOG_INFO, log_cb,
NULL, NULL, stderr) != 0) {
+5 -4
View File
@@ -48,7 +48,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <pthread.h>
#include "pthread-shim.h"
#ifdef _WIN32
#include <windows.h>
@@ -65,7 +65,7 @@
static struct rist_logging_settings *log_settings = NULL;
static pthread_mutex_t tracker_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t tracker_lock;
#define MAX_TRACKED_PEERS 16
static struct {
struct rist_peer *seen[MAX_TRACKED_PEERS];
@@ -130,7 +130,7 @@ static struct rist_ctx *start_receiver(const char *url, receiver_data_callback2_
return rx;
}
static void *sender_feed(void *arg) {
static PTHREAD_START_FUNC(sender_feed, arg) {
struct rist_ctx *tx = arg;
uint32_t counter = 0;
while (sender_run) {
@@ -143,7 +143,7 @@ static void *sender_feed(void *arg) {
counter++;
usleep(20000); /* ~50 pkt/s */
}
return NULL;
return 0;
}
int main(int argc, char *argv[]) {
@@ -157,6 +157,7 @@ int main(int argc, char *argv[]) {
return 99;
memset(&tracker, 0, sizeof(tracker));
pthread_mutex_init(&tracker_lock, NULL);
/* sender: listener, MAIN, shared PSK, streams data. */
struct rist_ctx *tx = NULL;