tests/testHttpRequest \
tests/testIcmp \
tests/testIpAddress \
+ tests/testNetDb \
tests/testStore \
tests/testString \
tests/testURL \
$(COMPAT_LIB) \
$(XTRA_LIBS)
+tests_testNetDb_SOURCES = \
+ tests/testNetDb.cc \
+ tests/testNetDb.h
+nodist_tests_testNetDb_SOURCES = \
+ SquidTime.h \
+ tests/stub_debug.cc \
+ tests/stub_libmem.cc \
+ time.cc \
+ globals.cc
+tests_testNetDb_LDFLAGS = $(LIBADD_DL)
+tests_testNetDb_LDADD = \
+ icmp/libicmp.la \
+ ip/libip.la \
+ base/libbase.la \
+ $(top_builddir)/lib/libmisccontainers.la \
+ $(LIBCPPUNIT_LIBS) \
+ $(COMPAT_LIB) \
+ $(XTRA_LIBS)
+
## Tests for ip/* objects
tests_testIpAddress_SOURCES= \
tests/testAddress.cc \
if (n->link_count == 0) {
netdbHashDelete(n->network);
- memFree(n, MEM_NETDBENTRY);
+ delete n;
}
}
int k = 0;
int list_count = 0;
int removed = 0;
- list = (netdbEntry **)xcalloc(memInUse(MEM_NETDBENTRY), sizeof(netdbEntry *));
+ list = (netdbEntry **)xcalloc(netdbEntry::UseCount(), sizeof(netdbEntry *));
hash_first(addr_table);
while ((n = (netdbEntry *) hash_next(addr_table))) {
- assert(list_count < memInUse(MEM_NETDBENTRY));
+ assert(list_count < netdbEntry::UseCount());
*(list + list_count) = n;
++list_count;
}
netdbLRU);
for (k = 0; k < list_count; ++k) {
- if (memInUse(MEM_NETDBENTRY) < Config.Netdb.low)
+ if (netdbEntry::UseCount() < Config.Netdb.low)
break;
netdbRelease(*(list + k));
{
netdbEntry *n;
- if (memInUse(MEM_NETDBENTRY) > Config.Netdb.high)
+ if (netdbEntry::UseCount() > Config.Netdb.high)
netdbPurgeLRU();
if ((n = netdbLookupAddr(addr)) == NULL) {
- n = (netdbEntry *)memAllocate(MEM_NETDBENTRY);
+ n = new netdbEntry;
netdbHashInsert(n, addr);
}
N.last_use_time = (time_t) atoi(q);
- n = (netdbEntry *)memAllocate(MEM_NETDBENTRY);
+ n = new netdbEntry;
memcpy(n, &N, sizeof(netdbEntry));
{
netdbEntry *n = (netdbEntry *)data;
safe_free(n->peers);
- memFree(n, MEM_NETDBENTRY);
+ delete n;
}
static void
}
}
-static void
-netdbRegisterWithCacheManager(void)
-{
- Mgr::RegisterAction("netdb", "Network Measurement Database", netdbDump, 0, 1);
-}
-
#endif /* USE_ICMP */
/* PUBLIC FUNCTIONS */
netdbInit(void)
{
#if USE_ICMP
- int n;
-
- netdbRegisterWithCacheManager();
+ Mgr::RegisterAction("netdb", "Network Measurement Database", netdbDump, 0, 1);
if (addr_table)
return;
- n = hashPrime(Config.Netdb.high / 4);
+ int n = hashPrime(Config.Netdb.high / 4);
addr_table = hash_create((HASHCMP *) strcmp, n, hash_string);
"RTT",
"Hops",
"Hostnames");
- list = (netdbEntry **)xcalloc(memInUse(MEM_NETDBENTRY), sizeof(netdbEntry *));
+ list = (netdbEntry **)xcalloc(netdbEntry::UseCount(), sizeof(netdbEntry *));
i = 0;
hash_first(addr_table);
++i;
}
- if (i != memInUse(MEM_NETDBENTRY))
+ if (i != netdbEntry::UseCount())
debugs(38, DBG_CRITICAL, "WARNING: netdb_addrs count off, found " << i <<
- ", expected " << memInUse(MEM_NETDBENTRY));
+ ", expected " << netdbEntry::UseCount());
qsort((char *) list,
i,
time_t expires;
};
-// POD
class netdbEntry
{
+ MEMPROXY_CLASS(netdbEntry);
+
public:
+ netdbEntry() { *network = 0; }
+
hash_link hash; /* must be first */
char network[MAX_IPSTRLEN];
- int pings_sent;
- int pings_recv;
- double hops;
- double rtt;
- time_t next_ping_time;
- time_t last_use_time;
- int link_count;
- net_db_name *hosts;
- net_db_peer *peers;
- int n_peers_alloc;
- int n_peers;
+ int pings_sent = 0;
+ int pings_recv = 0;
+ double hops = 0;
+ double rtt = 1.0;
+ time_t next_ping_time = 0;
+ time_t last_use_time = 0;
+ int link_count = 0;
+ net_db_name *hosts = nullptr;
+ net_db_peer *peers = nullptr;
+ int n_peers_alloc = 0;
+ int n_peers = 0;
};
void netdbInit(void);
#ifndef _SQUID_SRC_IP_ADDRESS_H
#define _SQUID_SRC_IP_ADDRESS_H
+#include "ip/forward.h"
+
#include <iosfwd>
#include <ostream>
#if HAVE_SYS_SOCKET_H
namespace Ip
{
-/// Length of buffer that needs to be allocated to old a null-terminated IP-string
-// Yuck. But there are still structures that need it to be an 'integer constant'.
-#define MAX_IPSTRLEN 75
-
/**
* Holds and manipulates IPv4, IPv6, and Socket Addresses.
*/
class Address;
}
+/// Length of buffer that needs to be allocated to old a null-terminated IP-string
+// Yuck. But there are still structures that need it to be an 'integer constant'.
+#define MAX_IPSTRLEN 75
+
typedef uint32_t nfmark_t;
typedef unsigned char tos_t;
MEM_DREAD_CTRL,
MEM_DWRITE_Q,
MEM_MD5_DIGEST,
- MEM_NETDBENTRY,
MEM_MAX
} mem_type;
memDataInit(MEM_LINK_LIST, "link_list", sizeof(link_list), 10);
memDataInit(MEM_DREAD_CTRL, "dread_ctrl", sizeof(dread_ctrl), 0);
memDataInit(MEM_DWRITE_Q, "dwrite_q", sizeof(dwrite_q), 0);
- memDataInit(MEM_NETDBENTRY, "netdbEntry", sizeof(netdbEntry), 0);
memDataInit(MEM_MD5_DIGEST, "MD5 digest", SQUID_MD5_DIGEST_LENGTH, 0);
GetPool(MEM_MD5_DIGEST)->setChunkSize(512 * 1024);
--- /dev/null
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "icmp/net_db.h"
+#include "tests/testNetDb.h"
+#include "unitTestMain.h"
+
+#include <stdexcept>
+
+CPPUNIT_TEST_SUITE_REGISTRATION( testNetDb );
+
+void
+testNetDb::testConstruct()
+{
+ // default construct and destruct
+ {
+ netdbEntry T;
+ CPPUNIT_ASSERT_EQUAL(T.network[0], '\0');
+ CPPUNIT_ASSERT_EQUAL(0, T.pings_sent);
+ CPPUNIT_ASSERT_EQUAL(0, T.pings_recv);
+ CPPUNIT_ASSERT_EQUAL(0.0, T.hops);
+ CPPUNIT_ASSERT_EQUAL(1.0, T.rtt);
+ CPPUNIT_ASSERT_EQUAL(static_cast<time_t>(0), T.next_ping_time);
+ CPPUNIT_ASSERT_EQUAL(static_cast<time_t>(0), T.last_use_time);
+ CPPUNIT_ASSERT_EQUAL(0, T.link_count);
+ CPPUNIT_ASSERT_EQUAL(static_cast<net_db_name*>(nullptr), T.hosts);
+ CPPUNIT_ASSERT_EQUAL(static_cast<net_db_peer*>(nullptr), T.peers);
+ CPPUNIT_ASSERT_EQUAL(0, T.n_peers_alloc);
+ CPPUNIT_ASSERT_EQUAL(0, T.n_peers);
+ }
+
+ // new and delete operations
+ {
+ netdbEntry *T = new netdbEntry;
+ CPPUNIT_ASSERT_EQUAL(T->network[0], '\0');
+ CPPUNIT_ASSERT_EQUAL(0, T->pings_sent);
+ CPPUNIT_ASSERT_EQUAL(0, T->pings_recv);
+ CPPUNIT_ASSERT_EQUAL(0.0, T->hops);
+ CPPUNIT_ASSERT_EQUAL(1.0, T->rtt);
+ CPPUNIT_ASSERT_EQUAL(static_cast<time_t>(0), T->next_ping_time);
+ CPPUNIT_ASSERT_EQUAL(static_cast<time_t>(0), T->last_use_time);
+ CPPUNIT_ASSERT_EQUAL(0, T->link_count);
+ CPPUNIT_ASSERT_EQUAL(static_cast<net_db_name*>(nullptr), T->hosts);
+ CPPUNIT_ASSERT_EQUAL(static_cast<net_db_peer*>(nullptr), T->peers);
+ CPPUNIT_ASSERT_EQUAL(0, T->n_peers_alloc);
+ CPPUNIT_ASSERT_EQUAL(0, T->n_peers);
+ delete T;
+ }
+}
+
--- /dev/null
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SRC_TESTS_TESTNETDB_H
+#define SQUID_SRC_TESTS_TESTNETDB_H
+
+#include <cppunit/extensions/HelperMacros.h>
+
+class testNetDb : public CPPUNIT_NS::TestFixture
+{
+ CPPUNIT_TEST_SUITE( testNetDb );
+ /* note the statement here and then the actual prototype below */
+ CPPUNIT_TEST( testConstruct );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+
+protected:
+ void testConstruct();
+};
+
+#endif /* SQUID_SRC_TESTS_TESTNETDB_H */
+