From 5f5768318f897a20464ca177b5de64157afe0938 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Tue, 10 Oct 2023 16:57:22 -0700 Subject: [PATCH 1/1] server: Bind port before messing with log files as a lock Rather than messing with flock, fnctl-F_SETLK, etc., just bind the port before touching the log file & let the failure to bind the port keep two instances of the server from stepping on each others' log i/o. --- server/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index 5edadbb..e7351db 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -93,9 +93,9 @@ fn open_log_for_writing() -> csv::Writer { } fn main() { - let mut log = open_log_for_writing(); - let mut presses = HashMap::::new(); let socket = UdpSocket::bind("0.0.0.0:29803").expect("couldn't bind to address"); + let mut presses = HashMap::::new(); + let mut log = open_log_for_writing(); loop { let mut buf = [0; MESSAGE_SIZE]; match socket.recv_from(&mut buf) { -- 2.44.1