Libevent Code Doxygen document
ratelim-internal.h
1 /*
2  * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 #ifndef RATELIM_INTERNAL_H_INCLUDED_
27 #define RATELIM_INTERNAL_H_INCLUDED_
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include "event2/util.h"
34 
41  ev_ssize_t read_limit, write_limit;
44  ev_uint32_t last_updated;
45 };
46 
50  size_t read_rate;
52  size_t read_maximum;
54  size_t write_rate;
56  size_t write_maximum;
57 
58  /* How long is a tick? Note that fractions of a millisecond are
59  * ignored. */
60  struct timeval tick_timeout;
61 
62  /* How long is a tick, in milliseconds? Derived from tick_timeout. */
63  unsigned msec_per_tick;
64 };
65 
68 int ev_token_bucket_update_(struct ev_token_bucket *bucket,
69  const struct ev_token_bucket_cfg *cfg,
70  ev_uint32_t current_tick);
71 
74 ev_uint32_t ev_token_bucket_get_tick_(const struct timeval *tv,
75  const struct ev_token_bucket_cfg *cfg);
76 
82 int ev_token_bucket_init_(struct ev_token_bucket *bucket,
83  const struct ev_token_bucket_cfg *cfg,
84  ev_uint32_t current_tick,
85  int reinitialize);
86 
87 int bufferevent_remove_from_rate_limit_group_internal_(struct bufferevent *bev,
88  int unsuspend);
89 
91 #define ev_token_bucket_decrement_read(b,n) \
92  do { \
93  (b)->read_limit -= (n); \
94  } while (0)
96 #define ev_token_bucket_decrement_write(b,n) \
97  do { \
98  (b)->write_limit -= (n); \
99  } while (0)
100 
101 #ifdef __cplusplus
102 }
103 #endif
104 
105 #endif
Definition: bufferevent_struct.h:70
Definition: ratelim-internal.h:48
size_t read_maximum
Definition: ratelim-internal.h:52
size_t write_maximum
Definition: ratelim-internal.h:56
size_t write_rate
Definition: ratelim-internal.h:54
size_t read_rate
Definition: ratelim-internal.h:50
Definition: ratelim-internal.h:38
ev_ssize_t read_limit
Definition: ratelim-internal.h:41
ev_uint32_t last_updated
Definition: ratelim-internal.h:44