⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 otime.h

📁 OpenVPN is a robust and highly flexible tunneling application that uses all of the encryption, authe
💻 H
字号:
/* *  OpenVPN -- An application to securely tunnel IP networks *             over a single TCP/UDP port, with support for SSL/TLS-based *             session authentication and key exchange, *             packet encryption, packet authentication, and *             packet compression. * *  Copyright (C) 2002-2004 James Yonan <jim@yonan.net> * *  This program 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 2 of the License, or *  (at your option) any later version. * *  This program 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 this program (see the file COPYING included with this *  distribution); if not, write to the Free Software Foundation, Inc., *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *//* * The interval_ routines are designed to optimize the calling of a routine * (normally tls_multi_process()) which can be called less frequently * between triggers. */#ifndef OTIME_H#define OTIME_H#include "common.h"#include "integer.h"#include "buffer.h"#include "thread.h"struct frequency_limit{  int max;  int per;  int n;  time_t reset;};struct frequency_limit *frequency_limit_init (int max, int per);void frequency_limit_free (struct frequency_limit *f);bool frequency_limit_event_allowed (struct frequency_limit *f);#ifdef WIN32int gettimeofday(struct timeval *tv, void *tz);#endif/* format a time_t as ascii, or use current time if 0 */const char* time_string (time_t t, int usec, bool show_usec, struct gc_arena *gc);/* struct timeval functions */const char *tv_string (const struct timeval *tv, struct gc_arena *gc);const char *tv_string_abs (const struct timeval *tv, struct gc_arena *gc);extern volatile time_t now; /* updated frequently to time(NULL) */static inline voidupdate_time (void){  const time_t real_time = time (NULL);  if (real_time != now)    now = real_time;}static inline voidtv_clear (struct timeval *tv){  tv->tv_sec = 0;  tv->tv_usec = 0;}static inline booltv_defined (const struct timeval *tv){  return tv->tv_sec > 0 && tv->tv_usec > 0;}/* return tv1 - tv2 in usec, constrained by max_seconds */static inline inttv_subtract (const struct timeval *tv1, const struct timeval *tv2, const unsigned int max_seconds){  const int max_usec = max_seconds * 1000000;  const int sec_diff = tv1->tv_sec - tv2->tv_sec;  if (sec_diff > ((int)max_seconds + 10))    return max_usec;  else if (sec_diff < -((int)max_seconds + 10))    return -max_usec;  return constrain_int (sec_diff * 1000000 + (tv1->tv_usec - tv2->tv_usec), -max_usec, max_usec);}static inline voidtv_add (struct timeval *dest, const struct timeval *src){  dest->tv_sec += src->tv_sec;  dest->tv_usec += src->tv_usec;  dest->tv_sec += (dest->tv_usec >> 20);  dest->tv_usec &= 0x000FFFFF;  if (dest->tv_usec >= 1000000)    {      dest->tv_usec -= 1000000;      dest->tv_sec += 1;    } }static inline booltv_lt (const struct timeval *t1, const struct timeval *t2){  if (t1->tv_sec < t2->tv_sec)    return true;  else if (t1->tv_sec > t2->tv_sec)    return false;  else    return t1->tv_usec < t2->tv_usec;}static inline booltv_le (const struct timeval *t1, const struct timeval *t2){  if (t1->tv_sec < t2->tv_sec)    return true;  else if (t1->tv_sec > t2->tv_sec)    return false;  else    return t1->tv_usec <= t2->tv_usec;}static inline booltv_ge (const struct timeval *t1, const struct timeval *t2){  if (t1->tv_sec > t2->tv_sec)    return true;  else if (t1->tv_sec < t2->tv_sec)    return false;  else    return t1->tv_usec >= t2->tv_usec;}static inline booltv_gt (const struct timeval *t1, const struct timeval *t2){  if (t1->tv_sec > t2->tv_sec)    return true;  else if (t1->tv_sec < t2->tv_sec)    return false;  else    return t1->tv_usec > t2->tv_usec;}static inline booltv_eq (const struct timeval *t1, const struct timeval *t2){  return t1->tv_sec == t2->tv_sec && t1->tv_usec == t2->tv_usec;}static inline voidtv_delta (struct timeval *dest, const struct timeval *t1, const struct timeval *t2){  int sec = t2->tv_sec - t1->tv_sec;  int usec = t2->tv_usec - t1->tv_usec;  while (usec < 0)    {      usec += 1000000;      sec -= 1;    }  if (sec < 0)    usec = sec = 0;  dest->tv_sec = sec;  dest->tv_usec = usec;}#define TV_WITHIN_SIGMA_MAX_SEC 600#define TV_WITHIN_SIGMA_MAX_USEC (TV_WITHIN_SIGMA_MAX_SEC * 1000000)/* * Is t1 and t2 within sigma microseconds of each other? */static inline booltv_within_sigma (const struct timeval *t1, const struct timeval *t2, unsigned int sigma){  const int delta = tv_subtract (t1, t2, TV_WITHIN_SIGMA_MAX_SEC); /* sigma should be less than 10 minutes */  return -(int)sigma <= delta && delta <= (int)sigma;}/* * Used to determine in how many seconds we should be * called again. */static inline voidinterval_earliest_wakeup (interval_t *wakeup, time_t at, time_t current) {  if (at > current)    {      const interval_t delta = (interval_t) (at - current);      if (delta < *wakeup)	*wakeup = delta;      if (*wakeup < 0)	*wakeup = 0;    }}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -