nmsg  0.9.0
rate.c
1 /*
2  * Copyright (c) 2008, 2009, 2012, 2013 by Farsight Security, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /* Import. */
18 
19 #include "private.h"
20 
21 #include "libmy/my_rate.h"
22 
23 /* Data structures. */
24 
25 struct nmsg_rate {
26  struct my_rate *rate;
27 };
28 
29 /* Export. */
30 
31 nmsg_rate_t
32 nmsg_rate_init(unsigned rate_param, unsigned freq_param) {
33  struct nmsg_rate *r;
34  struct my_rate *rate;
35 
36  rate = my_rate_init(rate_param, freq_param);
37  if (rate == NULL)
38  return (NULL);
39 
40  r = calloc(1, sizeof(*r));
41  if (r == NULL) {
42  my_rate_destroy(&rate);
43  return (NULL);
44  }
45 
46  r->rate = rate;
47 
48  return (r);
49 }
50 
51 void
52 nmsg_rate_destroy(nmsg_rate_t *r) {
53  if (*r != NULL) {
54  my_rate_destroy(&(*r)->rate);
55  free(*r);
56  *r = NULL;
57  }
58 }
59 
60 void
61 nmsg_rate_sleep(nmsg_rate_t r) {
62  my_rate_sleep(r->rate);
63 }
void nmsg_rate_sleep(nmsg_rate_t r)
Sleep if necessary to maintain the target rate limit.
Definition: rate.c:61
void nmsg_rate_destroy(nmsg_rate_t *r)
Destroy an nmsg_rate_t object.
Definition: rate.c:52
nmsg_rate_t nmsg_rate_init(unsigned rate, unsigned freq)
Initialize a new nmsg_rate_t object.
Definition: rate.c:32