6fbf66fa |
/*
* OpenVPN -- An application to securely tunnel IP networks
* over a single UDP port, with support for SSL/TLS-based
* session authentication and key exchange,
* packet encryption, packet authentication, and
* packet compression.
* |
49979459 |
* Copyright (C) 2002-2018 OpenVPN Inc <sales@openvpn.net> |
6fbf66fa |
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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.
* |
caa54ac3 |
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
6fbf66fa |
*/
|
c110b289 |
#ifdef HAVE_CONFIG_H
#include "config.h"
#elif defined(_MSC_VER)
#include "config-msvc.h"
#endif
|
6fbf66fa |
#include "syshead.h"
#include "shaper.h"
#include "memdbg.h"
|
3d163bc5 |
#ifdef ENABLE_FEATURE_SHAPER |
6fbf66fa |
/*
* We want to wake up in delay microseconds. If timeval is larger
* than delay, set timeval to delay.
*/
bool |
81d882d5 |
shaper_soonest_event(struct timeval *tv, int delay) |
6fbf66fa |
{ |
81d882d5 |
bool ret = false;
if (delay < 1000000) |
6fbf66fa |
{ |
81d882d5 |
if (tv->tv_sec)
{
tv->tv_sec = 0;
tv->tv_usec = delay;
ret = true;
}
else if (delay < tv->tv_usec)
{
tv->tv_usec = delay;
ret = true;
} |
6fbf66fa |
} |
81d882d5 |
else |
6fbf66fa |
{ |
81d882d5 |
const int sec = delay / 1000000;
const int usec = delay % 1000000; |
6fbf66fa |
|
81d882d5 |
if (sec < tv->tv_sec)
{
tv->tv_sec = sec;
tv->tv_usec = usec;
ret = true;
}
else if (sec == tv->tv_sec)
{
if (usec < tv->tv_usec)
{
tv->tv_usec = usec;
ret = true;
}
} |
6fbf66fa |
}
#ifdef SHAPER_DEBUG |
06ad53e0 |
dmsg(D_SHAPER_DEBUG, "SHAPER shaper_soonest_event sec=%"PRIi64" usec=%ld ret=%d",
(int64_t)tv->tv_sec, (long)tv->tv_usec, (int)ret); |
6fbf66fa |
#endif |
81d882d5 |
return ret; |
6fbf66fa |
}
void |
81d882d5 |
shaper_reset_wakeup(struct shaper *s) |
6fbf66fa |
{ |
81d882d5 |
CLEAR(s->wakeup); |
6fbf66fa |
}
void |
81d882d5 |
shaper_msg(struct shaper *s) |
6fbf66fa |
{ |
81d882d5 |
msg(M_INFO, "Output Traffic Shaping initialized at %d bytes per second",
s->bytes_per_second); |
6fbf66fa |
}
|
81d882d5 |
#else /* ifdef ENABLE_FEATURE_SHAPER */
static void |
4cd4899e |
dummy(void)
{ |
81d882d5 |
} |
3d163bc5 |
#endif /* ENABLE_FEATURE_SHAPER */ |