minidlna support now Samsung TV C550/C650 (thx amir909)
[tomato.git] / release / src / router / openvpn / interval.c
blobfcda4b7255feb14cc73d5bc38e7ccb1643a778cc
1 /*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
8 * Copyright (C) 2002-2009 OpenVPN Technologies, Inc. <sales@openvpn.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (see the file COPYING included with this
21 * distribution); if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "syshead.h"
27 #include "interval.h"
29 #include "memdbg.h"
31 void
32 interval_init (struct interval *top, int horizon, int refresh)
34 CLEAR (*top);
35 top->refresh = refresh;
36 top->horizon = horizon;
39 bool
40 event_timeout_trigger (struct event_timeout *et,
41 struct timeval *tv,
42 const int et_const_retry)
44 bool ret = false;
45 const time_t local_now = now;
47 if (et->defined)
49 int wakeup = (int) et->last + et->n - local_now;
50 if (wakeup <= 0)
52 #if INTERVAL_DEBUG
53 dmsg (D_INTERVAL, "EVENT event_timeout_trigger (%d) etcr=%d", et->n, et_const_retry);
54 #endif
55 if (et_const_retry < 0)
57 et->last = local_now;
58 wakeup = et->n;
59 ret = true;
61 else
63 wakeup = et_const_retry;
67 if (tv && wakeup < tv->tv_sec)
69 #if INTERVAL_DEBUG
70 dmsg (D_INTERVAL, "EVENT event_timeout_wakeup (%d/%d) etcr=%d", wakeup, et->n, et_const_retry);
71 #endif
72 tv->tv_sec = wakeup;
73 tv->tv_usec = 0;
76 return ret;