From f844abb037cc8206489f8a168fcfa8a46a2de36f Mon Sep 17 00:00:00 2001 From: des Date: Sat, 16 Sep 2006 14:50:09 +0000 Subject: [PATCH] Add a non-blocking mode to the log reader. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1025 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/include/varnishapi.h | 1 + varnish-cache/lib/libvarnishapi/shmlog.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/varnish-cache/include/varnishapi.h b/varnish-cache/include/varnishapi.h index 772fedd6..a6734b12 100644 --- a/varnish-cache/include/varnishapi.h +++ b/varnish-cache/include/varnishapi.h @@ -22,6 +22,7 @@ struct VSL_data; struct VSL_data *VSL_New(void); void VSL_Select(struct VSL_data *vd, unsigned tag); int VSL_OpenLog(struct VSL_data *vd); +void VSL_NonBlocking(struct VSL_data *vd, int nb); int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv); int VSL_NextLog(struct VSL_data *lh, unsigned char **pp); int VSL_Arg(struct VSL_data *vd, int arg, const char *opt); diff --git a/varnish-cache/lib/libvarnishapi/shmlog.c b/varnish-cache/lib/libvarnishapi/shmlog.c index aef5ad3f..f25c5866 100644 --- a/varnish-cache/lib/libvarnishapi/shmlog.c +++ b/varnish-cache/lib/libvarnishapi/shmlog.c @@ -42,6 +42,7 @@ struct VSL_data { unsigned flags; #define F_SEEN_IX (1 << 0) +#define F_NON_BLOCKING (1 << 1) unsigned char map[NFD]; #define M_CLIENT (1 << 0) @@ -165,6 +166,17 @@ VSL_OpenLog(struct VSL_data *vd) /*--------------------------------------------------------------------*/ +void +VSL_NonBlocking(struct VSL_data *vd, int nb) +{ + if (nb) + vd->flags |= F_NON_BLOCKING; + else + vd->flags &= ~F_NON_BLOCKING; +} + +/*--------------------------------------------------------------------*/ + static int vsl_nextlog(struct VSL_data *vd, unsigned char **pp) { @@ -191,6 +203,8 @@ vsl_nextlog(struct VSL_data *vd, unsigned char **pp) continue; } if (*p == SLT_ENDMARKER) { + if (vd->flags & F_NON_BLOCKING) + return (-1); w += SLEEP_USEC; usleep(SLEEP_USEC); continue; -- 2.39.5