From 41b5da75acf3ea476e493707f13d74ed9c5eb008 Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Sun, 11 Jun 2023 22:04:25 +0200 Subject: [PATCH] New env var SOCAT_TRANSFER_WAIT: sleep before transfer loop --- CHANGES | 5 +++++ VERSION | 2 +- doc/socat.yo | 10 +++++++++- socat.c | 5 +++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 7704d10..c0b02f8 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,9 @@  +Coding: + New Environment variable SOCAT_TRANSFER_WAIT that Socat sleep before + starting the data transfer loop. Useful, e.g., to accumulate multiple + packets in a receiving datagram socket before starting to process them. + ####################### V 1.7.4.4: Corrections: diff --git a/VERSION b/VERSION index ba76462..732830e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -"1.7.4.4" +"1.7.4.4+" diff --git a/doc/socat.yo b/doc/socat.yo index 49ab0dd..4f40ddb 100644 --- a/doc/socat.yo +++ b/doc/socat.yo @@ -3652,8 +3652,16 @@ address format. If name resolution does not return a matching entry, the first result (with differing IP version) is taken. With value 0, socat always selects the first record and its IP version. +dit(bf(SOCAT_MAIN_WAIT) (input)) Specifies the time (seconds) to sleep the +main process on begin of main\(). Useful for debugging. + +dit(bf(SOCAT_TRANSFER_WAIT) (input)) Specifies the time (seconds) to sleep the +process after opening addresses before entering the transfer loop. Useful for +debugging. + dit(bf(SOCAT_FORK_WAIT) (input)) Specifies the time (seconds) to sleep the -parent and child processes after successful NOEXPAND(fork()). Useful for debugging. +parent and child processes after successful NOEXPAND(fork()). Useful for +debugging. dit(bf(SOCAT_VERSION) (output)) Socat sets this variable to its version string, e.g. tt("1.7.0.0") for released versions or e.g. tt("1.6.0.1+envvar") for diff --git a/socat.c b/socat.c index 85540d9..41f69a7 100644 --- a/socat.c +++ b/socat.c @@ -782,6 +782,7 @@ bool maywr2; /* sock2 can be written to, according to poll() */ and their options are set/applied returns -1 on error or 0 on success */ int _socat(void) { + char *transferwaitstring; struct pollfd fds[4], *fd1in = &fds[0], *fd1out = &fds[1], @@ -851,6 +852,10 @@ int _socat(void) { } total_timeout = socat_opts.total_timeout; + if (transferwaitstring = getenv("SOCAT_TRANSFER_WAIT")) { + Info1("before starting data transfer loop: sleeping %ds (env:SOCAT_TRANSFER_WAIT)", atoi(transferwaitstring)); + sleep(atoi(transferwaitstring)); + } Notice4("starting data transfer loop with FDs [%d,%d] and [%d,%d]", XIO_GETRDFD(sock1), XIO_GETWRFD(sock1), XIO_GETRDFD(sock2), XIO_GETWRFD(sock2));