[sr-dev] git:master:8ead5ae6: modules/statsd: combine sock structure and error tracking variable
Mikko Lehto
mslehto at iki.fi
Fri Jan 29 10:04:17 CET 2016
Module: kamailio
Branch: master
Commit: 8ead5ae6f4cd0b64226a838fcc03c9beca219d98
URL: https://github.com/kamailio/kamailio/commit/8ead5ae6f4cd0b64226a838fcc03c9beca219d98
Author: Mikko Lehto <mslehto at iki.fi>
Committer: Mikko Lehto <mslehto at iki.fi>
Date: 2016-01-26T00:36:01+02:00
modules/statsd: combine sock structure and error tracking variable
---
Modified: modules/statsd/lib_statsd.c
Modified: modules/statsd/lib_statsd.h
---
Diff: https://github.com/kamailio/kamailio/commit/8ead5ae6f4cd0b64226a838fcc03c9beca219d98.diff
Patch: https://github.com/kamailio/kamailio/commit/8ead5ae6f4cd0b64226a838fcc03c9beca219d98.patch
---
diff --git a/modules/statsd/lib_statsd.c b/modules/statsd/lib_statsd.c
index dedb41b..76744f0 100644
--- a/modules/statsd/lib_statsd.c
+++ b/modules/statsd/lib_statsd.c
@@ -11,47 +11,40 @@
#include "../../sr_module.h"
#include "lib_statsd.h"
-static StatsdSocket statsd_socket = {
- "/var/run/statsd/statsd.sock",
- -1,
- 500, // timeout 500ms if no answer
- 0,
- ""
-};
-
static StatsConnection statsd_connection = {
"127.0.0.1",
- "8125"
+ "8125",
+ -1
};
bool statsd_connect(void){
struct addrinfo *serverAddr;
- int rc, error;
+ int rc;
- if (statsd_socket.sock > 0){
+ if (statsd_connection.sock > 0){
return true;
}
- error = getaddrinfo(
+ rc = getaddrinfo(
statsd_connection.ip, statsd_connection.port,
NULL, &serverAddr);
- if (error != 0)
+ if (rc != 0)
{
LM_ERR(
"Statsd: could not initiate server information (%s)\n",
- gai_strerror(error));
+ gai_strerror(rc));
return false;
}
- statsd_socket.sock = socket(serverAddr->ai_family, SOCK_DGRAM, IPPROTO_UDP);
- if (statsd_socket.sock == 0 ){
+ statsd_connection.sock = socket(serverAddr->ai_family, SOCK_DGRAM, IPPROTO_UDP);
+ if (statsd_connection.sock == 0 ){
LM_ERR("Statsd: could not initiate a connect to statsd\n");
return false;
}
rc = connect(
- statsd_socket.sock, serverAddr->ai_addr, serverAddr->ai_addrlen);
+ statsd_connection.sock, serverAddr->ai_addr, serverAddr->ai_addrlen);
freeaddrinfo(serverAddr);
if (rc < 0){
LM_ERR("Statsd: could not initiate a connect to statsd\n");
@@ -67,7 +60,7 @@ bool send_command(char *command){
return false;
}
- send_result = send(statsd_socket.sock, command, strlen(command), 0);
+ send_result = send(statsd_connection.sock, command, strlen(command), 0);
if ( send_result < 0){
LM_ERR("could not send the correct info to statsd (%i| %s)\n",
send_result, strerror(errno));
@@ -129,6 +122,6 @@ bool statsd_init(char *ip, char *port){
}
bool statsd_destroy(void){
- statsd_socket.sock = 0;
+ statsd_connection.sock = 0;
return true;
}
diff --git a/modules/statsd/lib_statsd.h b/modules/statsd/lib_statsd.h
index d3064c2..a80482c 100644
--- a/modules/statsd/lib_statsd.h
+++ b/modules/statsd/lib_statsd.h
@@ -5,16 +5,9 @@
typedef struct StatsConnection{
char *ip;
char *port;
+ int sock;
} StatsConnection;
-typedef struct StatsdSocket {
- char *name; // name
- int sock; // socket
- int timeout; // how many miliseconds to wait for an answer
- time_t last_failure; // time of the last failure
- char data[BUFFER_SIZE]; // buffer for the answer data
-} StatsdSocket;
-
bool statsd_connect(void);
bool send_command(char *command);
bool statsd_set(char *key, char *value);
More information about the sr-dev
mailing list