From 062c36a2f387392f11225c901582181adf5c7401 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Fri, 12 Jun 2020 02:09:46 +0200 Subject: [PATCH] libipc now uses 64-bit float (double) timers. --- Makefile | 24 ++++++++++++------------ examples/pongd.c | 4 ++-- project.zsh | 2 +- src/communication.c | 11 ++++++----- src/ipc.h | 4 ++-- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 9e992b9..4a29984 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PACKAGE = 'libipc' -VERSION = '0.5.1' +VERSION = '0.6.0' PREFIX := /usr/local BINDIR := $(PREFIX)/bin @@ -50,25 +50,25 @@ libipc.so: src/communication.o src/error.o src/fs.o src/message.o src/network.o $(Q)$(CC) -o libipc.so -shared $(LDFLAGS) src/communication.o src/error.o src/fs.o src/message.o src/network.o src/print.o src/usocket.o src/utils.o libipc.so.install: libipc.so - @echo ' IN > $(LIBDIR)/libipc.so.0.5.1' + @echo ' IN > $(LIBDIR)/libipc.so.0.6.0' $(Q)mkdir -p '$(DESTDIR)$(LIBDIR)' - $(Q)install -m0755 libipc.so $(DESTDIR)$(LIBDIR)/libipc.so.0.5.1 - @echo ' LN > $(LIBDIR)/libipc.so.0.5' - $(Q)ln -sf '$(LIBDIR)/libipc.so.0.5.1' '$(DESTDIR)/$(LIBDIR)/libipc.so.0.5' + $(Q)install -m0755 libipc.so $(DESTDIR)$(LIBDIR)/libipc.so.0.6.0 + @echo ' LN > $(LIBDIR)/libipc.so.0.6' + $(Q)ln -sf '$(LIBDIR)/libipc.so.0.6.0' '$(DESTDIR)/$(LIBDIR)/libipc.so.0.6' @echo ' LN > $(LIBDIR)/libipc.so.0' - $(Q)ln -sf '$(LIBDIR)/libipc.so.0.5.1' '$(DESTDIR)/$(LIBDIR)/libipc.so.0' + $(Q)ln -sf '$(LIBDIR)/libipc.so.0.6.0' '$(DESTDIR)/$(LIBDIR)/libipc.so.0' @echo ' LN > $(LIBDIR)/libipc.so' - $(Q)ln -sf '$(LIBDIR)/libipc.so.0.5.1' '$(DESTDIR)/$(LIBDIR)/libipc.so' + $(Q)ln -sf '$(LIBDIR)/libipc.so.0.6.0' '$(DESTDIR)/$(LIBDIR)/libipc.so' libipc.so.clean: @echo ' RM > libipc.so' $(Q)rm -f libipc.so libipc.so.uninstall: - @echo ' RM > $(LIBDIR)/libipc.so.0.5.1' - $(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.5.1' - @echo ' RM > $(LIBDIR)/libipc.so.0.5' - $(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.5' + @echo ' RM > $(LIBDIR)/libipc.so.0.6.0' + $(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.6.0' + @echo ' RM > $(LIBDIR)/libipc.so.0.6' + $(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.6' @echo ' RM > $(LIBDIR)/libipc.so.0' $(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0' @echo ' RM > $(LIBDIR)/libipc.so' @@ -297,7 +297,7 @@ $(PACKAGE)-$(VERSION).tar.bz2: distdir $(PACKAGE)-$(VERSION)/src/utils.h help: - @echo ' :: libipc-0.5.1' + @echo ' :: libipc-0.6.0' @echo '' @echo 'Generic targets:' @echo ' - help  Prints this help message.' diff --git a/examples/pongd.c b/examples/pongd.c index 15bcb08..fa80447 100644 --- a/examples/pongd.c +++ b/examples/pongd.c @@ -21,8 +21,8 @@ struct ipc_connection_infos *clients = NULL; void main_loop () { - long base_timer = 0; - long timer = base_timer; + double base_timer = 0; + double timer = base_timer; SECURE_DECLARATION (struct ipc_error, ret); clients = malloc (sizeof (struct ipc_connection_infos)); diff --git a/project.zsh b/project.zsh index 8a8b8e2..ccc3e60 100644 --- a/project.zsh +++ b/project.zsh @@ -1,6 +1,6 @@ package=libipc # Package name. -version=0.5.1 # Package version. +version=0.6.0 # Package version. # Our targets are the library and its documentation. targets=(libipc man/libipc.7) diff --git a/src/communication.c b/src/communication.c index 7650e40..bd5eeb1 100644 --- a/src/communication.c +++ b/src/communication.c @@ -368,7 +368,7 @@ struct ipc_error handle_message (struct ipc_event *event, struct ipc_connection_ struct ipc_error ipc_wait_event_networkd (struct ipc_connection_infos *cinfos , struct ipc_connection_info *cinfo // NULL for clients , struct ipc_event *event, struct ipc_switchings *switchdb - , long *timer) + , double *timer) { T_R ((cinfos == NULL), IPC_ERROR_WAIT_EVENT__NO_CLIENTS_PARAM); T_R ((event == NULL), IPC_ERROR_WAIT_EVENT__NO_EVENT_PARAM); @@ -410,15 +410,16 @@ struct ipc_error ipc_wait_event_networkd (struct ipc_connection_infos *cinfos struct timeval *ptimeout = NULL; SECURE_DECLARATION (struct timeval, timeout); - if (timer != NULL && *timer > 0) { - timeout.tv_sec = *timer; + if (timer != NULL && *timer > 0.0) { + timeout.tv_sec = (long) *timer; + timeout.tv_usec = (long) ((long)((*timer) * 1000000) % 1000000); ptimeout = &timeout; } T_PERROR_RIPC ((select (fdmax + 1, &readf, NULL, NULL, ptimeout) == -1), "select", IPC_ERROR_WAIT_EVENT__SELECT); if (ptimeout != NULL) { - *timer = timeout.tv_sec; + *timer = (double) timeout.tv_sec + (timeout.tv_usec / 1000000.0); if (*timer == 0) { IPC_EVENT_SET (event, IPC_EVENT_TYPE_TIMER, NULL, NULL); IPC_RETURN_NO_ERROR; @@ -444,7 +445,7 @@ struct ipc_error ipc_wait_event_networkd (struct ipc_connection_infos *cinfos struct ipc_error ipc_wait_event (struct ipc_connection_infos *cinfos , struct ipc_connection_info *cinfo // NULL for clients - , struct ipc_event *event, long *timer) + , struct ipc_event *event, double *timer) { return ipc_wait_event_networkd (cinfos, cinfo, event, NULL, timer); } diff --git a/src/ipc.h b/src/ipc.h index 21fe210..a28ac20 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -251,7 +251,7 @@ struct ipc_error ipc_write (const struct ipc_connection_info *, const struct ipc struct ipc_error ipc_wait_event (struct ipc_connection_infos *clients , struct ipc_connection_info *srv - , struct ipc_event *event, long *timer); + , struct ipc_event *event, double *timer); // store and remove only pointers on allocated structures struct ipc_error ipc_add (struct ipc_connection_infos *, struct ipc_connection_info *); @@ -324,7 +324,7 @@ struct networkd { struct ipc_error ipc_wait_event_networkd (struct ipc_connection_infos *cinfos , struct ipc_connection_info *cinfo // cinfo is NULL for clients - , struct ipc_event *event, struct ipc_switchings *switchdb, long *timer); + , struct ipc_event *event, struct ipc_switchings *switchdb, double *timer); void ipc_switching_add (struct ipc_switchings *is, int orig, int dest); int ipc_switching_del (struct ipc_switchings *is, int fd);