fnet.c

Simple C networking library
git clone git://git.finwo.net/lib/fnet.c
Log | Files | Refs | README

commit 0d7b3c08fdb3c7ea1109a976369b72255b67d1a3
parent 89fb50d2c2680c2b2e6c3e922b84d259e451c853
Author: Yersa Nordman <yersa@finwo.nl>
Date:   Sun, 22 Oct 2023 21:20:12 +0200

Split time fetching linux and windows

Diffstat:
Msrc/fnet.c | 17++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/fnet.c b/src/fnet.c @@ -6,19 +6,20 @@ extern "C" { #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/timeb.h> #include <fcntl.h> #include <sys/types.h> -#include <netinet/tcp.h> #include <sys/epoll.h> #ifdef _WIN32 +#include <sys/timeb.h> #include <winsock2.h> #include <Ws2tcpip.h> #else #include <netdb.h> +#include <netinet/tcp.h> #include <sys/socket.h> +#include <sys/time.h> #include <unistd.h> #endif @@ -73,9 +74,15 @@ int setnonblock(int fd) { } int64_t _fnet_now() { - struct timeb tb; - ftime(&tb); - return (1000 * (int64_t)tb.time) + tb.millitm; +#if defined(_WIN32) || defined(_WIN64) + struct _timeb timebuffer; + _ftime(&timebuffer); + return (int64_t)(((timebuffer.time * 1000) + timebuffer.millitm)); +#else + struct timeval tv; + gettimeofday(&tv, NULL); + return (tv.tv_sec * ((int64_t)1000)) + (tv.tv_usec / 1000); +#endif } // CAUTION: assumes options have been vetted