File: results.cpp

package info (click to toggle)
postal 0.70
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 540 kB
  • ctags: 525
  • sloc: cpp: 4,131; sh: 289; ansic: 258; makefile: 134
file content (83 lines) | stat: -rw-r--r-- 1,184 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <stdio.h>
#include "postal.h"
#include "results.h"

results::results()
 : m_connections(0)
#ifdef USE_SSL
 , m_ssl_connections(0)
#endif
 , m_mut(true)
 , m_msgs(0)
 , m_bytes(0)
 , m_errors(0)
{
}

results::~results()
{
  m_print();
}

void results::error()
{
  Lock l(m_mut);
  m_errors++;
}

void results::dataBytes(int bytes)
{
  Lock l(m_mut);
  m_bytes += bytes;
}

void results::message()
{
  Lock l(m_mut);
  m_msgs++;
}

void results::connection()
{
  Lock l(m_mut);
  m_connections++;
}

#ifdef USE_SSL
void results::connect_ssl()
{
  Lock l(m_mut);
  m_ssl_connections++;
}
#endif

void results::print()
{
  Lock l(m_mut);
  m_print();
}

void results::childPrint()
{
}

void results::m_print()
{
  time_t now = time(NULL);
    tm *t = localtime(&now);
    printf("%02d:%02d,%d,%d,%d", t->tm_hour, t->tm_min, m_msgs
                               , m_bytes / 1024, m_errors);
#ifdef USE_SSL
    printf(",%d,%d", m_connections, m_ssl_connections);
    m_ssl_connections = 0;
#else
    printf(",%d", m_connections);
#endif
    childPrint();
    printf("\n");
    fflush(NULL);
    m_msgs = 0;
    m_connections = 0;
    m_bytes = m_bytes % 1024;
    m_errors = 0;
}