From ca27b26c6bf45a68a273a6a362403feb898b305a Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 5 Jan 2019 13:49:58 +0100 Subject: [PATCH] Avoid 2nd start of the simulation server udp_server() is being called second time during the simulated run, which fails due to trying to claim already used port. This patch adds cache to the udp_server() result. Signed-off-by: Szczepan Zalega --- pc/device.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pc/device.c b/pc/device.c index 4344ef5..ce915eb 100644 --- a/pc/device.c +++ b/pc/device.c @@ -54,7 +54,11 @@ void device_set_status(int status) int udp_server() { - int fd; + static bool run_already = false; + static int fd = -1; + if (run_already && fd >= 0) return fd; + run_already = true; + if ( (fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) { perror( "socket failed" ); return 1;