From a0e1742861607eded6176fa1583d6cd63ac2b39f Mon Sep 17 00:00:00 2001 From: bol-van Date: Tue, 19 Nov 2024 10:12:39 +0300 Subject: [PATCH] tpws: rate limit fix-seg errors without --debug --- tpws/tpws_conn.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tpws/tpws_conn.c b/tpws/tpws_conn.c index 5b9559f..696da8a 100644 --- a/tpws/tpws_conn.c +++ b/tpws/tpws_conn.c @@ -1118,8 +1118,24 @@ static ssize_t send_oob(int fd, uint8_t *buf, size_t len, int ttl, bool oob, uin } +static unsigned int segfail_count=0; +static time_t segfail_report_time=0; +static void report_segfail(void) +{ + time_t now = time(NULL); + segfail_count++; + if (now==segfail_report_time) + VPRINT("WARNING ! segmentation failed. total fails : %u\n", segfail_count); + else + { + DLOG_ERR("WARNING ! segmentation failed. total fails : %u\n", segfail_count); + segfail_report_time = now; + } +} + #define RD_BLOCK_SIZE 65536 #define MAX_WASTE (1024*1024) + static bool handle_epoll(tproxy_conn_t *conn, struct tailhead *conn_list, uint32_t evt) { int numbytes; @@ -1239,12 +1255,12 @@ static bool handle_epoll(tproxy_conn_t *conn, struct tailhead *conn_list, uint32 if (wasted) VPRINT("WARNING ! wasted %u ms to fix segmenation\n", wasted); if (!bWaitOK) - DLOG_ERR("WARNING ! segmentation failed\n"); + report_segfail(); } else { if (socket_has_notsent(conn->partner->fd)) - DLOG_ERR("WARNING ! segmentation failed\n"); + report_segfail(); } #endif VPRINT("Sending multisplit part %d %zd-%zd (len %zd)%s%s : ", i+1, from, to, len, bApplyDisorder ? " with disorder" : "", bApplyOOB ? " with OOB" : "");