source: trunk/libtransmission/history.c

Last change on this file was 14241, checked in by jordan, 7 years ago

Copyedit the license's revised text: (1) remove unnecessary repitition use of the word 'license' from the top of the header and source files (2) add the standard 'we hope it's useful, but no warranty' clause to COPYING (3) make explicit that linking OpenSSL is allowed (see https://people.gnome.org/~markmc/openssl-and-the-gpl.html for background) (4) sync the Qt and GTK+ clients' license popups with COPYING's revised text

  • Property svn:keywords set to Date Rev Author Id
File size: 1.1 KB
Line 
1/*
2 * This file Copyright (C) 2010-2014 Mnemosyne LLC
3 *
4 * It may be used under the GNU GPL versions 2 or 3
5 * or any future license endorsed by Mnemosyne LLC.
6 *
7 * $Id: history.c 14241 2014-01-21 03:10:30Z mikedld $
8 */
9
10#include <assert.h>
11#include <string.h> /* memset () */
12
13#include "transmission.h"
14#include "history.h"
15#include "utils.h"
16
17void
18tr_historyAdd (tr_recentHistory * h, time_t now, unsigned int n)
19{
20  if (h->slices[h->newest].date == now)
21    {
22      h->slices[h->newest].n += n;
23    }
24  else
25    {
26      if (++h->newest == TR_RECENT_HISTORY_PERIOD_SEC)
27        h->newest = 0;
28      h->slices[h->newest].date = now;
29      h->slices[h->newest].n = n;
30    }
31}
32
33unsigned int
34tr_historyGet (const tr_recentHistory * h, time_t now, unsigned int sec)
35{
36  unsigned int n = 0;
37  const time_t cutoff = (now?now:tr_time ()) - sec;
38  int i = h->newest;
39
40  for (;;)
41    {
42      if (h->slices[i].date <= cutoff)
43        break;
44
45      n += h->slices[i].n;
46
47      if (--i == -1)
48        i = TR_RECENT_HISTORY_PERIOD_SEC - 1; /* circular history */
49
50      if (i == h->newest)
51        break; /* we've come all the way around */
52    }
53
54  return n;
55}
Note: See TracBrowser for help on using the repository browser.