From 0d499a8da2310909e04099db558b7823f4df3837 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Wed, 14 Aug 2013 12:32:33 +0300 Subject: New function tbf.sleep * src/Makefile.am: Add new file. * src/sleep.c: New file. * src/vmod-tbf.3: Document the sleep call. * src/vmod_tbf.vcc (sleep): New function. --- src/Makefile.am | 1 + src/sleep.c | 33 +++++++++++++++++++++++++++++++++ src/vmod-tbf.3 | 7 ++++++- src/vmod_tbf.vcc | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/sleep.c diff --git a/src/Makefile.am b/src/Makefile.am index e2f9f11..727d33b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,6 +29,7 @@ libvmod_tbf_la_LIBADD= libvmod_tbf_la_SOURCES = \ getla.c\ + sleep.c\ time.c\ tbf.c\ vcc_if.c vcc_if.h diff --git a/src/sleep.c b/src/sleep.c new file mode 100644 index 0000000..70c4337 --- /dev/null +++ b/src/sleep.c @@ -0,0 +1,33 @@ +/* This file is part of vmod-tbf + Copyright (C) 2013 Sergey Poznyakoff + + Vmod-tbf is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + Vmod-tbf is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with vmod-tbf. If not, see . +*/ +#include +#include +#include +#include "vrt.h" +#include "vcc_if.h" + +void +vmod_sleep(struct sess *sp, double t) +{ + struct timespec ts, ret; + + ts.tv_sec = t; + ts.tv_nsec = (t - ts.tv_sec) * 1e9; + + while (nanosleep(&ts, &ret) && errno == EINTR) + ts = ret; +} diff --git a/src/vmod-tbf.3 b/src/vmod-tbf.3 index bd7b233..3521f0b 100644 --- a/src/vmod-tbf.3 +++ b/src/vmod-tbf.3 @@ -13,7 +13,7 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with vmod-tbf. If not, see . -.TH VMOD-TBF 1 "August 2, 2013" "VMOD-TBF" "User Reference" +.TH VMOD-TBF 1 "August 14, 2013" "VMOD-TBF" "User Reference" .SH NAME vmod-tbf \- token bucket filtering for Varnish .SH SYNOPSIS @@ -33,6 +33,8 @@ vmod-tbf \- token bucket filtering for Varnish .BI "STRING tbf.strftime(STRING " format ", INT " timestamp ");" +.BI "VOID tbf.sleep(DURATION " time ");" + .SH DESCRIPTION The .B vmod-tbf @@ -186,6 +188,9 @@ statements assigns the current year to the \f(CWX\-Year\fR header: .EX set req.http.X-Year = tbf.strftime("%Y", systime()); .EE +.PP +The \fBtbf.sleep\fR function suspends execution for a specified amount +of time. .\" The INCFILE variable is set by man.cgi script on Ulysses when .\" it finds the vmod-tbf.3.inc file located in the same directory .\" as this one. diff --git a/src/vmod_tbf.vcc b/src/vmod_tbf.vcc index 637c4f8..3634807 100644 --- a/src/vmod_tbf.vcc +++ b/src/vmod_tbf.vcc @@ -8,3 +8,4 @@ Function BOOL check(STRING, STRING) Function REAL getla(INT) Function INT systime() Function STRING strftime(STRING, INT) +Function VOID sleep(DURATION) -- cgit v1.2.1