• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 13494306182

24 Feb 2025 09:01AM UTC coverage: 60.607% (-1.6%) from 62.24%
13494306182

Pull #15203

github

web-flow
Merge 023bafd01 into 83beff6d6
Pull Request #15203: rec: switch back to serde_yaml

34838 of 90428 branches covered (38.53%)

Branch coverage included in aggregate %.

25 of 25 new or added lines in 1 file covered. (100.0%)

6482 existing lines in 72 files now uncovered.

120907 of 166548 relevant lines covered (72.6%)

4692544.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.29
/pdns/recursordist/rec-tcpout.cc
1
/*
2
 * This file is part of PowerDNS or dnsdist.
3
 * Copyright -- PowerDNS.COM B.V. and its contributors
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of version 2 of the GNU General Public License as
7
 * published by the Free Software Foundation.
8
 *
9
 * In addition, for the avoidance of any doubt, permission is granted to
10
 * link this program with OpenSSL and to (re)distribute the binaries
11
 * produced as the result of such linking.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22

23
#include "rec-tcpout.hh"
24

25
// This line from /usr/include/openssl/ssl2.h: # define CERT char
26
// throws dnsrecords.hh off the rails.
27
#undef CERT
28

29
#include "syncres.hh"
30

31
timeval TCPOutConnectionManager::s_maxIdleTime;
32
size_t TCPOutConnectionManager::s_maxQueries;
33
size_t TCPOutConnectionManager::s_maxIdlePerAuth;
34
size_t TCPOutConnectionManager::s_maxIdlePerThread;
35

36
void TCPOutConnectionManager::cleanup(const struct timeval& now)
37
{
174✔
38
  if (s_maxIdleTime.tv_sec == 0 && s_maxIdleTime.tv_usec == 0) {
174!
39
    // no maximum idle time
40
    return;
×
41
  }
×
42

43
  for (auto it = d_idle_connections.begin(); it != d_idle_connections.end();) {
174!
44
    timeval idle = now - it->second.d_last_used;
×
45
    if (s_maxIdleTime < idle) {
×
46
      it = d_idle_connections.erase(it);
×
47
    }
×
48
    else {
×
49
      ++it;
×
50
    }
×
51
  }
×
52
}
174✔
53

54
void TCPOutConnectionManager::store(const struct timeval& now, const ComboAddress& ip, Connection&& connection)
UNCOV
55
{
×
UNCOV
56
  ++connection.d_numqueries;
×
UNCOV
57
  if (s_maxQueries > 0 && connection.d_numqueries >= s_maxQueries) {
×
58
    return;
×
59
  }
×
60

UNCOV
61
  if (d_idle_connections.size() >= s_maxIdlePerThread || d_idle_connections.count(ip) >= s_maxIdlePerAuth) {
×
62
    cleanup(now);
×
63
  }
×
64

UNCOV
65
  if (d_idle_connections.size() >= s_maxIdlePerThread) {
×
66
    return;
×
67
  }
×
UNCOV
68
  if (d_idle_connections.count(ip) >= s_maxIdlePerAuth) {
×
69
    return;
×
70
  }
×
71

UNCOV
72
  gettimeofday(&connection.d_last_used, nullptr);
×
UNCOV
73
  d_idle_connections.emplace(ip, std::move(connection));
×
UNCOV
74
}
×
75

76
TCPOutConnectionManager::Connection TCPOutConnectionManager::get(const ComboAddress& ip)
UNCOV
77
{
×
UNCOV
78
  if (d_idle_connections.count(ip) > 0) {
×
UNCOV
79
    auto h = d_idle_connections.extract(ip);
×
UNCOV
80
    return h.mapped();
×
UNCOV
81
  }
×
UNCOV
82
  return Connection{};
×
UNCOV
83
}
×
84

85
uint64_t getCurrentIdleTCPConnections()
86
{
90✔
87
  return broadcastAccFunction<uint64_t>([] { return t_tcp_manager.getSize(); });
576✔
88
}
90✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc