diff options
author | Norbert Preining <norbert@preining.info> | 2020-09-20 03:03:26 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-09-20 03:03:26 +0000 |
commit | 1f457376b478257b88d4a857f5ec1b6155442dd7 (patch) | |
tree | 2a06a60551dea362cf8cb0cb0ba66c78608717c4 /support/dktools/dk-recv.ctr | |
parent | ac690ca29ad5bf8a5203a65fd6252f7b564f4727 (diff) |
CTAN sync 202009200303
Diffstat (limited to 'support/dktools/dk-recv.ctr')
-rw-r--r-- | support/dktools/dk-recv.ctr | 207 |
1 files changed, 177 insertions, 30 deletions
diff --git a/support/dktools/dk-recv.ctr b/support/dktools/dk-recv.ctr index c00d3c458c..e538024226 100644 --- a/support/dktools/dk-recv.ctr +++ b/support/dktools/dk-recv.ctr @@ -2,7 +2,7 @@ copyright owner = Dirk Krause copyright year = 2015-xxxx -license = bsd +SPDX-License-Identifier: BSD-3-Clause @@ -10,8 +10,13 @@ license = bsd #include "dk4conf.h" -#if DK4_HAVE_MATH_H +#if DK4_HAVE_MATH_H #ifndef MATH_H_INCLUDED +#if DK4_ON_WINDOWS +#ifndef _USE_MATH_DEFINES +#define _USE_MATH_DEFINES 1 +#endif +#endif #include <math.h> #define MATH_H_INCLUDED 1 #endif @@ -52,6 +57,14 @@ license = bsd #include "dk4mema.h" #include "dk4strd.h" #include "dk4pathd.h" +#include "dk4unused.h" +#include "dk4time.h" +#include "dk4maadu.h" +#include "dk4maodd.h" + +#ifndef DK4WMAIN_H_INCLUDED +#include "dk4wmain.h" +#endif @@ -96,7 +109,8 @@ This software uses code from the following projects, either directly or as a library: dktools Dirk Krause's tools and libraries. - See http://dktools.sourceforge.net/ for more information. + See http://sourceforge.net/p/dktools/wiki/Home/ + for more information. #if DK4_HAVE_ZLIB_H zlib Data compression library. @@ -123,27 +137,27 @@ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of the Dirk Krause nor the names of contributors may be - used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. - -IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. #if DK4_HAVE_ZLIB_H @@ -288,6 +302,20 @@ Wrong number of arguments!\n\thost port [filename] Interrupted by SIGINT signal! Interrupted by SIGTERM signal! Interrupted by SIGPIPE signal! +# +# 11 12 13 +# +Connect time: +Transfer time: +Transfer size: +# +# 14 15 +# + seconds. + bytes. +# +# +# $!end }; @@ -312,6 +340,12 @@ static const dk4_option_specification_t dk_recv_options[] = { +/** Error report for size calculations and statistics. +*/ +static dk4_er_t ernb; + + + /** Array of localized texts, loaded in the main() function. Usable as long as the app pointer below is usable. */ @@ -330,6 +364,10 @@ static const dkChar *dk_recv_portno = NULL; static dk4_app_t *app = NULL; +/** Number of bytes received. +*/ +dk4_um_t numbytes = (dk4_um_t)0UL; + /** Number of elements in the dk_recv_options array. */ @@ -338,11 +376,12 @@ sizeof(dk_recv_options)/sizeof(dk4_option_specification_t); +#if 0 /** Number of elements in the dk_recv_kw_def array. */ static const size_t dk_recv_sz_def = sizeof(dk_recv_kw_def)/sizeof(DK4_PCDKCHAR) - 1; - +#endif /** Number of elements in the dk_recv_kw_def array. @@ -351,6 +390,20 @@ static size_t dk_recv_sz_loc = sizeof(dk_recv_kw_def)/sizeof(DK4_PCDKCHAR) - 1; +/** Timestamp for start of connection attempt. +*/ +static dk4_time_t time_stamp_1 = (dk4_time_t)0UL; + + +/** Timestamp start of data transfer. +*/ +static dk4_time_t time_stamp_2 = (dk4_time_t)0UL; + + +/** Timestamp end of data transfer. +*/ +static dk4_time_t time_stamp_3 = (dk4_time_t)0UL; + /** Seconds for timeout. */ @@ -421,8 +474,9 @@ sig_pass_pointer(DK4_VOLATILE dk4_sig_atomic_t *ptr) */ static void -sig_handler_pipe(int signo) +sig_handler_pipe(int DK4_ARG_UNUSED(signo) ) { + DK4_UNUSED_ARG(signo) *sig_pass_pointer(&sig_had_pipe) = 1; } #endif @@ -432,8 +486,9 @@ sig_handler_pipe(int signo) */ static void -sig_handler_int(int signo) +sig_handler_int(int DK4_ARG_UNUSED(signo) ) { + DK4_UNUSED_ARG(signo) *sig_pass_pointer(&sig_had_int) = 1; } @@ -442,8 +497,9 @@ sig_handler_int(int signo) */ static void -sig_handler_term(int signo) +sig_handler_term(int DK4_ARG_UNUSED(signo) ) { + DK4_UNUSED_ARG(signo) *sig_pass_pointer(&sig_had_term) = 1; } @@ -467,10 +523,18 @@ sig_read_atomic(DK4_VOLATILE dk4_sig_atomic_t *ap) */ static int -sig_can_continue(int check_pipe) +sig_can_continue( +#ifdef SIGPIPE +int check_pipe +#else +int DK4_ARG_UNUSED(check_pipe) +#endif +) { int back = 1; -#ifdef SIGPIPE +#ifndef SIGPIPE + DK4_UNUSED_ARG(check_pipe) +#else if (0 != check_pipe) { if (0 != sig_read_atomic(&sig_had_pipe)) { back = 0; } } @@ -516,6 +580,81 @@ static char bu[1048576]; static char bu[16384]; #endif + + +/** Log statistical data (connect wait time, transfer time, transfer size). +*/ +static +void +log_statistics(void) +{ + dkChar b1[8*sizeof(dk4_um_t)]; /* Connect wait time */ + dkChar b2[8*sizeof(dk4_um_t)]; /* Transfer time */ + dkChar b3[8*sizeof(dk4_um_t)]; /* Transfer size */ + dkChar b4[8*sizeof(dk4_um_t)]; /* Space before number */ + const dkChar *msg[5]; + size_t sl1; + size_t sl2; + size_t sl3; + size_t slm; + size_t i; + + if ((time_stamp_2 >= time_stamp_1) && (time_stamp_3 >= time_stamp_2)) { + dk4ma_write_decimal_unsigned( + b1, DK4_SIZEOF(b1,dkChar), (time_stamp_2 - time_stamp_1), 0, &ernb + ); + dk4ma_write_decimal_unsigned( + b2, DK4_SIZEOF(b2,dkChar), (time_stamp_3 - time_stamp_2), 0, &ernb + ); + dk4ma_write_decimal_unsigned( + b3, DK4_SIZEOF(b3,dkChar), numbytes, 0, &ernb + ); + if (DK4_E_NONE == ernb.ec) { + sl1 = dk4str_len(b1); + sl2 = dk4str_len(b2); + sl3 = dk4str_len(b3); + slm = sl1; + if (sl2 > slm) slm = sl2; + if (sl3 > slm) slm = sl3; + /* + Number of connection seconds + */ + for (i = 0; i < (slm - sl1); i++) { b4[i] = dkT(' '); } + b4[(slm - sl1)] = dkT('\0'); + msg[0] = dk_recv_kw_loc[11]; + msg[1] = b4; + msg[2] = b1; + msg[3] = dk_recv_kw_loc[14]; + msg[4] = NULL; + dk4app_log_msg(app, DK4_LL_INFO, msg, 4); + /* + Number of transfer seconds + */ + for (i = 0; i < (slm - sl2); i++) { b4[i] = dkT(' '); } + b4[(slm - sl2)] = dkT('\0'); + msg[0] = dk_recv_kw_loc[12]; + msg[1] = b4; + msg[2] = b2; + msg[3] = dk_recv_kw_loc[14]; + msg[4] = NULL; + dk4app_log_msg(app, DK4_LL_INFO, msg, 4); + /* + Number of transferred bytes + */ + for (i = 0; i < (slm - sl3); i++) { b4[i] = dkT(' '); } + b4[(slm - sl3)] = dkT('\0'); + msg[0] = dk_recv_kw_loc[13]; + msg[1] = b4; + msg[2] = b3; + msg[3] = dk_recv_kw_loc[15]; + msg[4] = NULL; + dk4app_log_msg(app, DK4_LL_INFO, msg, 4); + } + } +} + + + /** Run for hostname, port specification and real file name (wildcards * and ? resolved on Windows). @param hostname Host to connect to (name or address). @@ -565,6 +704,7 @@ dk_recv_run_with_real_file_name( /* Open TCP client socket. */ + dk4time_get(&time_stamp_1); sock = dk4socket_tcp_client_for_host_service_app( hostname, portspec, dk_recv_portno, dk_recv_timeout_secs, dk_recv_timeout_usecs, app @@ -605,8 +745,10 @@ dk_recv_run_with_real_file_name( if (0 != sig_can_continue(1)) { $? ". can continue" sz = sizeof(bu); res = dk4socket_recv_app(sock, bu, &sz, 0, 0L, 0L, app); + if ((dk4_time_t)0UL == time_stamp_2) { dk4time_get(&time_stamp_2); } if (DK4_SOCKET_RESULT_SUCCESS == res) { if (0 < sz) { $? ". %u bytes found", (unsigned)sz + numbytes = dk4ma_um_add(numbytes, sz, &ernb); if (0 != sig_can_continue(1)) { if (0 != first) { $? ". first data packet" first = 0; @@ -654,6 +796,9 @@ dk_recv_run_with_real_file_name( cc = -1; } } while (1 == cc); + if ((dk4_time_t)0UL == time_stamp_2) { dk4time_get(&time_stamp_2); } + dk4time_get(&time_stamp_3); + /* Cleanup */ @@ -675,6 +820,7 @@ dk_recv_run_with_real_file_name( #endif } } + if (0 != dk4app_log_do(app, DK4_LL_INFO)) { log_statistics(); } /* Close socket if open. */ @@ -1058,6 +1204,7 @@ int main(int argc, char *argv[]) { $!trace-init dk-recv.deb $? "+ main" + dk4error_init(&ernb); dk4fput_initialize_stderr(); app = dk4app_open_cmd( argc, argv, dk_recv_options, dk_recv_sz_options, |