[master] 2bd3cea06 More double to vtim_* conversions

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Sat Nov 24 00:25:10 UTC 2018


commit 2bd3cea06afbff0aeeb00d04dbbdda5faf4779d1
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Sat Nov 24 01:07:09 2018 +0100

    More double to vtim_* conversions
    
    This may break out of tree code not respecting include order of vdef.h
    first (or via cache/cache.h). It's trivial to fix and forces consumers
    to follow the tracks.
    
    Refs #2791

diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 74c1973dd..c1da769d8 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -34,9 +34,6 @@
 #include <stdlib.h>
 #include <signal.h>
 
-#include "vtim.h"
-#include "vcs.h"
-
 #include "cache_varnishd.h"
 #include "cache_transport.h"
 
@@ -46,6 +43,8 @@
 
 #include "storage/storage.h"
 #include "vcli_serve.h"
+#include "vtim.h"
+#include "vcs.h"
 
 /*
  * The panic string is constructed in memory, then copied to the
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 4d074747b..c85331285 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -254,8 +254,8 @@ enum htc_status_e
 HTC_RxStuff(struct http_conn *htc, htc_complete_f *func,
     double *t1, double *t2, double ti, double tn, int maxbytes)
 {
-	double tmo;
-	double now;
+	vtim_dur tmo;
+	vtim_real now;
 	enum htc_status_e hs;
 	ssize_t z;
 
@@ -380,7 +380,7 @@ SES_New(struct pool *pp)
  */
 
 static void v_matchproto_(waiter_handle_f)
-ses_handle(struct waited *wp, enum wait_event ev, double now)
+ses_handle(struct waited *wp, enum wait_event ev, vtim_real now)
 {
 	struct sess *sp;
 	struct pool *pp;
@@ -517,7 +517,7 @@ SES_Close(struct sess *sp, enum sess_close reason)
  */
 
 void
-SES_Delete(struct sess *sp, enum sess_close reason, double now)
+SES_Delete(struct sess *sp, enum sess_close reason, vtim_real now)
 {
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index 08caa721b..a5a3d185b 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -75,8 +75,8 @@ struct http_conn {
 	void			*priv;
 
 	/* Timeouts */
-	double			first_byte_timeout;
-	double			between_bytes_timeout;
+	vtim_dur		first_byte_timeout;
+	vtim_dur		between_bytes_timeout;
 };
 
 typedef enum htc_status_e htc_complete_f(struct http_conn *);
diff --git a/bin/varnishtest/vtc_haproxy.c b/bin/varnishtest/vtc_haproxy.c
index 9d12ed671..846b5c8a8 100644
--- a/bin/varnishtest/vtc_haproxy.c
+++ b/bin/varnishtest/vtc_haproxy.c
@@ -105,7 +105,7 @@ struct haproxy_cli {
 	size_t			rxbuf_sz;
 	char			*rxbuf;
 
-	double			timeout;
+	vtim_dur		timeout;
 };
 
 /**********************************************************************
@@ -113,7 +113,7 @@ struct haproxy_cli {
  */
 
 static int
-haproxy_cli_tcp_connect(struct vtclog *vl, const char *addr, double tmo,
+haproxy_cli_tcp_connect(struct vtclog *vl, const char *addr, vtim_dur tmo,
     const char **errp)
 {
 	int fd;
diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c
index 4735472e2..43e300acf 100644
--- a/bin/varnishtest/vtc_logexp.c
+++ b/bin/varnishtest/vtc_logexp.c
@@ -116,11 +116,12 @@
 
 #include "vapi/vsm.h"
 #include "vapi/vsl.h"
-#include "vtim.h"
-#include "vre.h"
 
 #include "vtc.h"
 
+#include "vtim.h"
+#include "vre.h"
+
 #define LE_ANY  (-1)
 #define LE_LAST (-2)
 
diff --git a/bin/varnishtest/vtc_syslog.c b/bin/varnishtest/vtc_syslog.c
index 6318b6e39..e415d8c92 100644
--- a/bin/varnishtest/vtc_syslog.c
+++ b/bin/varnishtest/vtc_syslog.c
@@ -36,13 +36,13 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "vtc.h"
+
 #include "vsa.h"
 #include "vss.h"
 #include "vtcp.h"
 #include "vre.h"
 
-#include "vtc.h"
-
 struct syslog_srv {
 	unsigned			magic;
 #define SYSLOG_SRV_MAGIC		0xbf28a692
@@ -62,7 +62,7 @@ struct syslog_srv {
 	ssize_t				rxbuf_left;
 	size_t				rxbuf_sz;
 	char				*rxbuf;
-	double				timeout;
+	vtim_dur			timeout;
 };
 
 static pthread_mutex_t			syslog_mtx;
diff --git a/include/vrt.h b/include/vrt.h
index 8aabdbf83..19bdb7b08 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -158,7 +158,7 @@ typedef const struct vmod_priv *		VCL_BLOB;
 typedef const char *				VCL_BODY;
 typedef unsigned				VCL_BOOL;
 typedef int64_t					VCL_BYTES;
-typedef double					VCL_DURATION;
+typedef vtim_dur				VCL_DURATION;
 typedef const char *				VCL_ENUM;
 typedef const struct gethdr_s *			VCL_HEADER;
 typedef struct http *				VCL_HTTP;
@@ -170,7 +170,7 @@ typedef double					VCL_REAL;
 typedef const struct stevedore *		VCL_STEVEDORE;
 typedef const struct strands *			VCL_STRANDS;
 typedef const char *				VCL_STRING;
-typedef double					VCL_TIME;
+typedef vtim_real				VCL_TIME;
 typedef struct vcl *				VCL_VCL;
 typedef void					VCL_VOID;
 
@@ -213,7 +213,7 @@ struct vrt_ctx {
 	VCL_HTTP			http_bereq;
 	VCL_HTTP			http_beresp;
 
-	double				now;
+	vtim_real			now;
 
 	/*
 	 * method specific argument:
@@ -276,9 +276,9 @@ extern const void * const vrt_magic_string_unset;
 	rigid char			*port;			\
 	rigid char			*path;			\
 	rigid char			*hosthdr;		\
-	double				connect_timeout;	\
-	double				first_byte_timeout;	\
-	double				between_bytes_timeout;	\
+	vtim_dur			connect_timeout;	\
+	vtim_dur			first_byte_timeout;	\
+	vtim_dur			between_bytes_timeout;	\
 	unsigned			max_connections;	\
 	unsigned			proxy_header;
 
@@ -307,8 +307,8 @@ struct vrt_backend {
 };
 
 #define VRT_BACKEND_PROBE_FIELDS(rigid)				\
-	double				timeout;		\
-	double				interval;		\
+	vtim_dur			timeout;		\
+	vtim_dur			interval;		\
 	unsigned			exp_status;		\
 	unsigned			window;			\
 	unsigned			threshold;		\
diff --git a/include/vtcp.h b/include/vtcp.h
index 293759392..29f83cb75 100644
--- a/include/vtcp.h
+++ b/include/vtcp.h
@@ -55,13 +55,13 @@ void VTCP_name(const struct suckaddr *addr, char *abuf, unsigned alen,
     char *pbuf, unsigned plen);
 int VTCP_connected(int s);
 int VTCP_connect(const struct suckaddr *name, int msec);
-int VTCP_open(const char *addr, const char *def_port, double timeout,
+int VTCP_open(const char *addr, const char *def_port, vtim_dur timeout,
     const char **err);
 void VTCP_close(int *s);
 int VTCP_bind(const struct suckaddr *addr, const char **errp);
 int VTCP_listen(const struct suckaddr *addr, int depth, const char **errp);
 int VTCP_listen_on(const char *addr, const char *def_port, int depth,
     const char **errp);
-void VTCP_set_read_timeout(int s, double seconds);
-int VTCP_read(int fd, void *ptr, size_t len, double tmo);
+void VTCP_set_read_timeout(int s, vtim_dur seconds);
+int VTCP_read(int fd, void *ptr, size_t len, vtim_dur tmo);
 // #endif
diff --git a/include/vtim.h b/include/vtim.h
index 9c2e6ccfc..1968bc568 100644
--- a/include/vtim.h
+++ b/include/vtim.h
@@ -33,8 +33,8 @@ extern unsigned VTIM_postel;
 #define VTIM_FORMAT_SIZE 30
 void VTIM_format(double t, char *p);
 double VTIM_parse(const char *p);
-double VTIM_mono(void);
-double VTIM_real(void);
-void VTIM_sleep(double t);
-struct timespec VTIM_timespec(double t);
-struct timeval VTIM_timeval(double t);
+vtim_mono VTIM_mono(void);
+vtim_real VTIM_real(void);
+void VTIM_sleep(vtim_dur t);
+struct timespec VTIM_timespec(vtim_dur t);
+struct timeval VTIM_timeval(vtim_dur t);
diff --git a/lib/libvarnish/vev.c b/lib/libvarnish/vev.c
index 6e4e48c7d..e6459bc7d 100644
--- a/lib/libvarnish/vev.c
+++ b/lib/libvarnish/vev.c
@@ -353,7 +353,7 @@ VEV_Loop(struct vev_root *evb)
 /*--------------------------------------------------------------------*/
 
 static int
-vev_sched_timeout(struct vev_root *evb, struct vev *e, double t)
+vev_sched_timeout(struct vev_root *evb, struct vev *e, vtim_mono t)
 {
 	int i;
 
diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c
index 3294bbf08..972595ea0 100644
--- a/lib/libvarnish/vtcp.c
+++ b/lib/libvarnish/vtcp.c
@@ -51,6 +51,7 @@
 #include "vsa.h"
 #include "vss.h"
 #include "vtcp.h"
+#include "vtim.h"
 
 /*--------------------------------------------------------------------*/
 static void
@@ -345,12 +346,10 @@ VTCP_close(int *s)
 }
 
 void
-VTCP_set_read_timeout(int s, double seconds)
+VTCP_set_read_timeout(int s, vtim_dur seconds)
 {
 #ifdef SO_RCVTIMEO_WORKS
-	struct timeval timeout;
-	timeout.tv_sec = (int)floor(seconds);
-	timeout.tv_usec = (int)(1e6 * (seconds - timeout.tv_sec));
+	struct timeval timeout = VTIM_timeval(seconds);
 	/*
 	 * Solaris bug (present at least in snv_151 and older): If this fails
 	 * with EINVAL, the socket is half-closed (SS_CANTSENDMORE) and the
@@ -371,13 +370,14 @@ VTCP_set_read_timeout(int s, double seconds)
 static int v_matchproto_(vss_resolved_f)
 vtcp_open_callback(void *priv, const struct suckaddr *sa)
 {
+	/* XXX: vtim_dur? */
 	double *p = priv;
 
 	return (VTCP_connect(sa, (int)floor(*p * 1e3)));
 }
 
 int
-VTCP_open(const char *addr, const char *def_port, double timeout,
+VTCP_open(const char *addr, const char *def_port, vtim_dur timeout,
     const char **errp)
 {
 	int error;
@@ -592,7 +592,7 @@ VTCP_Check(int a)
  */
 
 int
-VTCP_read(int fd, void *ptr, size_t len, double tmo)
+VTCP_read(int fd, void *ptr, size_t len, vtim_dur tmo)
 {
 	struct pollfd pfd[1];
 	int i, j;


More information about the varnish-commit mailing list