#include "dnxStats.h"
#include "dnxDebug.h"
#include "dnxError.h"
#include <pthread.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
Go to the source code of this file.
Data Structures | |
struct | DnxNode |
The structure for managing stats for one client node, by IP address. More... | |
Defines | |
#define | elemcount(x) (sizeof(x)/sizeof(*(x))) |
Functions | |
static unsigned | hashFunction (struct sockaddr *addr) |
Return a 1-byte hash code for the specified address. | |
static int | dnxAddrCompare (struct sockaddr *addr_a, struct sockaddr *addr_b) |
Compare two addresses. | |
static DnxNode * | dnxCreateNodeAt (DnxNode **npp, struct sockaddr *saddr, unsigned hashCode) |
Create, insert, and return a new node with a specified address and hash. | |
static DnxNode * | dnxGetNode (struct sockaddr *saddr) |
Return a node matching an address. | |
void | dnxStatsGetServerStats (unsigned *statsbuf) |
Return a current snapshot of the server stats array. | |
void | dnxStatsResetServerStats (void) |
Reset all server stats to zero. | |
void | dnxStatsInc (char *addr, DnxStatsIndex member) |
Increment a member value from a single node. | |
int | dnxStatsForEachNode (DnxStatsNodeCB *cb, void *data) |
For each node in the list, call a method and pass some data. | |
int | dnxStatsForNodeByAddrStr (char *addrstr, DnxStatsNodeCB *cb, void *data) |
For the specified node, call a method and pass some data. | |
void | dnxStatsCleanup () |
A destructor for the stats management module. | |
Variables | |
static DnxNode * | s_nodeHashTable [256] |
The global node hash table. | |
static unsigned | s_serverStats [STATS_COUNT] |
The global server stats table. |
#define elemcount | ( | x | ) | (sizeof(x)/sizeof(*(x))) |
Definition at line 51 of file dnxStats.c.
static int dnxAddrCompare | ( | struct sockaddr * | addr_a, | |
struct sockaddr * | addr_b | |||
) | [static] |
Compare two addresses.
Only the network address portion of the address is compared; port numbers are ignored.
[in] | addr_a | - the first address to compare |
[in] | addr_b | - the second address to compare |
addr_a
is less than addr_b
. Zero if addr_a
is equal to addr_b
. A value greater than zero if addr_a
is greater than addr_b
. Definition at line 115 of file dnxStats.c.
static DnxNode* dnxCreateNodeAt | ( | DnxNode ** | npp, | |
struct sockaddr * | saddr, | |||
unsigned | hashCode | |||
) | [static] |
Create, insert, and return a new node with a specified address and hash.
The new node is inserted at the specified location in the hash table.
[in] | npp | - the location at which to store the new node. |
[in] | saddr | - the address for which a new node should be created. |
[in] | hashCode | - the previously calculated hash code for addr . |
Definition at line 147 of file dnxStats.c.
References DnxNodeData::address, DnxNodeData::addrstr, DnxNode::data, dnxNtop(), DnxNode::saddr, and xmalloc.
static DnxNode* dnxGetNode | ( | struct sockaddr * | saddr | ) | [static] |
Return a node matching an address.
NO LOCKS: Ensure caller is a single thread. (At least for the create case.)
Insert a new node and return it if missing.
[in] | saddr | - the address of the node to be returned. |
Definition at line 176 of file dnxStats.c.
References dnxAddrCompare(), dnxCreateNodeAt(), hashFunction(), DnxNode::next, and DnxNode::saddr.
void dnxStatsCleanup | ( | ) |
A destructor for the stats management module.
This function can be used to cleanup any resources allocated by this module before shutdown.
Definition at line 256 of file dnxStats.c.
References elemcount, and DnxNode::next.
int dnxStatsForEachNode | ( | DnxStatsNodeCB * | cb, | |
void * | data | |||
) |
For each node in the list, call a method and pass some data.
[in] | cb | - the node processing function to be called. |
[in] | data | - opaque data pointer passed to nodeProc. |
nodeProc
. Definition at line 219 of file dnxStats.c.
References DnxNode::data, DNX_CBCANCEL, elemcount, and DnxNode::next.
int dnxStatsForNodeByAddrStr | ( | char * | addrstr, | |
DnxStatsNodeCB * | cb, | |||
void * | data | |||
) |
For the specified node, call a method and pass some data.
[in] | addrstr | - the DNS or dotted decimal address of the node. |
[in] | cb | - the node processing function to be called. |
[in] | data | - opaque data pointer passed to nodeProc. |
nodeProc
. Definition at line 234 of file dnxStats.c.
References DnxNode::data, and dnxGetNode().
void dnxStatsGetServerStats | ( | unsigned * | statsbuf | ) |
Return a current snapshot of the server stats array.
The statsbuf
array should be at least STATS_COUNT elements in length.
[out] | statsbuf | - the address of storage for all server stats. |
Definition at line 192 of file dnxStats.c.
References s_serverStats.
void dnxStatsInc | ( | char * | addr, | |
DnxStatsIndex | member | |||
) |
Increment a member value from a single node.
[in] | addr | - the address of the node for which a stat should be incremented. This is the binary address, not the presentation address. |
[in] | member | - the stat to be incremented. |
Definition at line 206 of file dnxStats.c.
References DnxNode::data, dnxGetNode(), s_serverStats, DnxNodeData::stats, and STATS_COUNT.
void dnxStatsResetServerStats | ( | void | ) |
Reset all server stats to zero.
Definition at line 199 of file dnxStats.c.
References s_serverStats.
static unsigned hashFunction | ( | struct sockaddr * | addr | ) | [static] |
Return a 1-byte hash code for the specified address.
[in] | addr | - the address to be hashed. |
addr
is at LEAST 4 bytes long. Definition at line 77 of file dnxStats.c.
DnxNode* s_nodeHashTable[256] [static] |
unsigned s_serverStats[STATS_COUNT] [static] |