From 11ea4fcf515dbc4f75be538b784635085dc10db2 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 05:25:50 +0200 Subject: Merging upstream version 2.2.0+dfsg. Signed-off-by: Daniel Baumann --- include/util.h | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'include/util.h') diff --git a/include/util.h b/include/util.h index 0f28ce4..db0e66f 100644 --- a/include/util.h +++ b/include/util.h @@ -63,6 +63,8 @@ extern "C" { extern int sInterupted; +#define WARNBUFSIZE 256 + /* ------------------------------------------------------------------- * set/getsockopt wrappers for SO_RCVBUF and SO_SNDBUF; TCP_MAXSEG * socket.c @@ -119,6 +121,7 @@ BOOL WINAPI sig_dispatcher(DWORD type); * ------------------------------------------------------------------- */ void warn (const char *inMessage, const char *inFile, int inLine); void warn_errno(const char *inMessage, const char *inFile, int inLine); +int errno_decode (char *decoded_text, size_t len); #define FAIL_exit(cond, msg) \ do { \ @@ -192,12 +195,27 @@ double bitorbyte_atof(const char *inString); intmax_t byte_atoi(const char *inString); uintmax_t bitorbyte_atoi(const char *inString); void byte_snprintf(char* outString, int inLen, double inNum, char inFormat); - +void make_lower(char *s); /* * Time macros for C-code (not the include Timestamp.hpp) */ #define rMillion 1000000 + +#ifdef HAVE_CLOCK_GETTIME +#define TimeGetNow(timeval) do { \ + struct timespec t1; \ + clock_gettime(CLOCK_REALTIME, &t1); \ + timeval.tv_sec = t1.tv_sec; \ + timeval.tv_usec = t1.tv_nsec / 1000; \ +} while (0) +#else +#define TimeGetNow(timeval) do { \ + gettimeofday(&timeval, NULL); \ +} while (0) +#endif + + #define TimeZero(timeval) ((timeval.tv_sec == 0) && (timeval.tv_usec == 0)) #define TimeDifference(left, right) ((left.tv_sec - right.tv_sec) + \ @@ -217,6 +235,16 @@ void byte_snprintf(char* outString, int inLen, double inNum, char inFormat); left.tv_sec += right.tv_sec; \ } while (0) +#define TimeAddIntUsec(left, right) do { \ + left.tv_usec += right % 1000000; \ + if (left.tv_usec > rMillion) { \ + left.tv_usec -= rMillion; \ + left.tv_sec++; \ + } \ + left.tv_sec += right / 1000000; \ + } while (0) + + /* ------------------------------------------------------------------- * redirect the stdout to a specified file * stdio.c @@ -260,6 +288,8 @@ void redirect(const char *inOutputFileName); #define NONFATALTCPWRITERR(errno) ((errno = WSAGetLastError()) == WSAETIMEDOUT) #define FATALUDPWRITERR(errno) (((errno = WSAGetLastError()) != WSAETIMEDOUT) \ && (errno != WSAECONNREFUSED)) +#define FATALTCPCONNECTERR(errno) (((errno = WSAGetLastError()) != WSAETIMEDOUT) && \ + (errno != WSAECONNREFUSED) && (errno != WSAEWOULDBLOCK)) #else #define FATALTCPREADERR(errno) ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINTR)) #define FATALUDPREADERR(errno) ((errno != EAGAIN) && (errno != EWOULDBLOCK) && \ @@ -268,11 +298,11 @@ void redirect(const char *inOutputFileName); #define NONFATALTCPWRITERR(errno) (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) #define FATALUDPWRITERR(errno) ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINTR) \ && (errno != ECONNREFUSED) && (errno != ENOBUFS)) +#define FATALTCPCONNECTERR(errno) ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINTR) \ + && (errno != ECONNREFUSED)) #endif -#ifdef WIN32 -#else -#endif +#define IPERF_SOCKET_ERROR_NONFATAL -2 #ifdef __cplusplus } /* end extern "C" */ -- cgit v1.2.3