aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-08-14 12:32:33 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-08-14 12:32:33 +0300
commit0d499a8da2310909e04099db558b7823f4df3837 (patch)
treecf613f3c30600c87b8205896945243ded974ba96
parent76d9b5d569c7d0ac8e4b65ed63b6afa5a7999f90 (diff)
downloadvmod-tbf-0d499a8da2310909e04099db558b7823f4df3837.tar.gz
vmod-tbf-0d499a8da2310909e04099db558b7823f4df3837.tar.bz2
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.
-rw-r--r--src/Makefile.am1
-rw-r--r--src/sleep.c33
-rw-r--r--src/vmod-tbf.37
-rw-r--r--src/vmod_tbf.vcc1
4 files changed, 41 insertions, 1 deletions
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=
29 29
30libvmod_tbf_la_SOURCES = \ 30libvmod_tbf_la_SOURCES = \
31 getla.c\ 31 getla.c\
32 sleep.c\
32 time.c\ 33 time.c\
33 tbf.c\ 34 tbf.c\
34 vcc_if.c vcc_if.h 35 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 @@
1/* This file is part of vmod-tbf
2 Copyright (C) 2013 Sergey Poznyakoff
3
4 Vmod-tbf is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 Vmod-tbf is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with vmod-tbf. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include <config.h>
18#include <errno.h>
19#include <time.h>
20#include "vrt.h"
21#include "vcc_if.h"
22
23void
24vmod_sleep(struct sess *sp, double t)
25{
26 struct timespec ts, ret;
27
28 ts.tv_sec = t;
29 ts.tv_nsec = (t - ts.tv_sec) * 1e9;
30
31 while (nanosleep(&ts, &ret) && errno == EINTR)
32 ts = ret;
33}
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 @@
13.\" 13.\"
14.\" You should have received a copy of the GNU General Public License 14.\" You should have received a copy of the GNU General Public License
15.\" along with vmod-tbf. If not, see <http://www.gnu.org/licenses/>. 15.\" along with vmod-tbf. If not, see <http://www.gnu.org/licenses/>.
16.TH VMOD-TBF 1 "August 2, 2013" "VMOD-TBF" "User Reference" 16.TH VMOD-TBF 1 "August 14, 2013" "VMOD-TBF" "User Reference"
17.SH NAME 17.SH NAME
18vmod-tbf \- token bucket filtering for Varnish 18vmod-tbf \- token bucket filtering for Varnish
19.SH SYNOPSIS 19.SH SYNOPSIS
@@ -33,6 +33,8 @@ vmod-tbf \- token bucket filtering for Varnish
33 33
34.BI "STRING tbf.strftime(STRING " format ", INT " timestamp ");" 34.BI "STRING tbf.strftime(STRING " format ", INT " timestamp ");"
35 35
36.BI "VOID tbf.sleep(DURATION " time ");"
37
36.SH DESCRIPTION 38.SH DESCRIPTION
37The 39The
38.B vmod-tbf 40.B vmod-tbf
@@ -186,6 +188,9 @@ statements assigns the current year to the \f(CWX\-Year\fR header:
186.EX 188.EX
187set req.http.X-Year = tbf.strftime("%Y", systime()); 189set req.http.X-Year = tbf.strftime("%Y", systime());
188.EE 190.EE
191.PP
192The \fBtbf.sleep\fR function suspends execution for a specified amount
193of time.
189.\" The INCFILE variable is set by man.cgi script on Ulysses when 194.\" The INCFILE variable is set by man.cgi script on Ulysses when
190.\" it finds the vmod-tbf.3.inc file located in the same directory 195.\" it finds the vmod-tbf.3.inc file located in the same directory
191.\" as this one. 196.\" 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)
8Function REAL getla(INT) 8Function REAL getla(INT)
9Function INT systime() 9Function INT systime()
10Function STRING strftime(STRING, INT) 10Function STRING strftime(STRING, INT)
11Function VOID sleep(DURATION)

Return to:

Send suggestions and report system problems to the System administrator.