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=
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 <http://www.gnu.org/licenses/>.
+*/
+#include <config.h>
+#include <errno.h>
+#include <time.h>
+#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 <http://www.gnu.org/licenses/>.
-.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)

Return to:

Send suggestions and report system problems to the System administrator.