Get rid of dead code
[yazproxy-moved-to-github.git] / src / yaz-bw.cpp
1 /* $Id: yaz-bw.cpp,v 1.7 2005-06-25 15:58:33 adam Exp $
2    Copyright (c) 1998-2004, Index Data.
3
4 This file is part of the yaz-proxy.
5
6 YAZ proxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with YAZ proxy; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #include <time.h>
23 #include <yaz/log.h>
24 #include <yazproxy/bw.h>
25
26 Yaz_bw::Yaz_bw(int sz)
27 {
28     m_sec = 0;
29     m_size = sz;
30     m_bucket = new int[m_size];
31     m_ptr = 0;
32 }
33
34 Yaz_bw::~Yaz_bw()
35 {
36     delete [] m_bucket;
37 }
38
39 int Yaz_bw::get_total()
40 {
41     add_bytes(0);
42     int bw = 0;
43     int i;
44     for (i = 0; i<m_size; i++)
45         bw += m_bucket[i];
46     return bw;
47 }
48
49 void Yaz_bw::add_bytes(int b)
50 {
51     long now = time(0);
52
53     int d = now - m_sec;
54     if (d > m_size)
55         d = m_size;
56     while (--d >= 0)
57     {
58         if (++m_ptr == m_size)
59             m_ptr = 0;
60         m_bucket[m_ptr] = 0;
61     }
62     m_bucket[m_ptr] += b;
63     m_sec = now;
64 }
65
66 /*
67  * Local variables:
68  * c-basic-offset: 4
69  * indent-tabs-mode: nil
70  * End:
71  * vim: shiftwidth=4 tabstop=8 expandtab
72  */
73