ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/util.C
(Generate patch)

Comparing gvpe/src/util.C (file contents):
Revision 1.1 by pcg, Sat Mar 1 15:53:03 2003 UTC vs.
Revision 1.2 by pcg, Fri Mar 21 23:17:01 2003 UTC

45 45
46#include "global.h" 46#include "global.h"
47#include "conf.h" 47#include "conf.h"
48#include "slog.h" 48#include "slog.h"
49#include "protocol.h" 49#include "protocol.h"
50
51time_t now;
52 50
53int 51int
54write_pidfile (void) 52write_pidfile (void)
55{ 53{
56 int pid; 54 int pid;
142 140
143 if (!confbase) 141 if (!confbase)
144 asprintf (&confbase, "%s/vpe", CONFDIR); 142 asprintf (&confbase, "%s/vpe", CONFDIR);
145} 143}
146 144
147void pkt_queue::put (tap_packet *p)
148{
149 if (queue[i])
150 {
151 delete queue[i];
152 j = (j + 1) % QUEUEDEPTH;
153 }
154
155 queue[i] = p;
156
157 i = (i + 1) % QUEUEDEPTH;
158}
159
160tap_packet *pkt_queue::get ()
161{
162 tap_packet *p = queue[j];
163
164 if (p)
165 {
166 queue[j] = 0;
167 j = (j + 1) % QUEUEDEPTH;
168 }
169
170 return p;
171}
172
173pkt_queue::pkt_queue ()
174{
175 memset (queue, 0, sizeof (queue));
176 i = 0;
177 j = 0;
178}
179
180pkt_queue::~pkt_queue ()
181{
182 for (i = QUEUEDEPTH; --i > 0; )
183 delete queue[i];
184}
185
186sockinfo::operator const char *() 145sockinfo::operator const char *()
187{ 146{
188 static char hostport[15 + 1 + 5 + 1]; 147 static char hostport[15 + 1 + 5 + 1];
189 in_addr ia = { host }; 148 in_addr ia = { host };
190 149
191 sprintf (hostport, "%.15s:%d", inet_ntoa (ia), ntohs (port) & 0xffff); 150 sprintf (hostport, "%.15s:%d", inet_ntoa (ia), ntohs (port) & 0xffff);
192 151
193 return hostport; 152 return hostport;
194} 153}
195 154
196bool u32_rate_limiter::can (u32 host)
197{
198 iterator i;
199
200 for (i = begin (); i != end (); )
201 if (i->second <= now)
202 {
203 erase (i);
204 i = begin ();
205 }
206 else
207 ++i;
208
209 i = find (host);
210
211 if (i != end ())
212 return false;
213
214 insert (value_type (host, now + every));
215
216 return true;
217}
218

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines