Browse Source

* backend/mcast : add 'ping' option

master
Alex 'AdUser' Z 8 years ago
parent
commit
aef31fc2c8
  1. 1
      configs/conf-available/10-backend-mcast.conf
  2. 14
      src/backends/mcast.c

1
configs/conf-available/10-backend-mcast.conf

@ -1,4 +1,5 @@
[backend:mcast] [backend:mcast]
load = libf2b_backend_mcast.so load = libf2b_backend_mcast.so
; ping = 5
; group = 239.255.186.1 ; group = 239.255.186.1
; port = 3370 ; port = 3370

14
src/backends/mcast.c

@ -28,11 +28,14 @@
#define DEFAULT_MCAST_ADDR "239.255.186.1" #define DEFAULT_MCAST_ADDR "239.255.186.1"
#define DEFAULT_MCAST_PORT "3370" #define DEFAULT_MCAST_PORT "3370"
#define DEFAULT_PING_NUM 5
struct _config { struct _config {
char name[ID_MAX + 1]; char name[ID_MAX + 1];
char error[256]; char error[256];
bool shared; bool shared;
uint8_t ping_num; /*< current number of ping() call */
uint8_t ping_max; /*< max ping() calls before actually send CMD_PING packet */
char maddr[INET_ADDRSTRLEN]; /**< multicast address */ char maddr[INET_ADDRSTRLEN]; /**< multicast address */
char mport[6]; /**< multicast port */ char mport[6]; /**< multicast port */
char iface[IF_NAMESIZE]; /**< bind interface */ char iface[IF_NAMESIZE]; /**< bind interface */
@ -47,6 +50,7 @@ create(const char *id) {
if ((cfg = calloc(1, sizeof(cfg_t))) == NULL) if ((cfg = calloc(1, sizeof(cfg_t))) == NULL)
return NULL; return NULL;
cfg->ping_max = DEFAULT_PING_NUM;
strlcpy(cfg->name, id, sizeof(cfg->name)); strlcpy(cfg->name, id, sizeof(cfg->name));
strlcpy(cfg->maddr, DEFAULT_MCAST_ADDR, sizeof(cfg->maddr)); strlcpy(cfg->maddr, DEFAULT_MCAST_ADDR, sizeof(cfg->maddr));
strlcpy(cfg->mport, DEFAULT_MCAST_PORT, sizeof(cfg->mport)); strlcpy(cfg->mport, DEFAULT_MCAST_PORT, sizeof(cfg->mport));
@ -76,6 +80,10 @@ config(cfg_t *cfg, const char *key, const char *value) {
strlcpy(cfg->iface, value, sizeof(cfg->iface)); strlcpy(cfg->iface, value, sizeof(cfg->iface));
return true; return true;
} }
if (strcmp(key, "ping") == 0) {
cfg->ping_max = atoi(value);
return true;
}
return false; return false;
} }
@ -151,6 +159,12 @@ bool
ping(cfg_t *cfg) { ping(cfg_t *cfg) {
assert(cfg != NULL); assert(cfg != NULL);
cfg->ping_num++;
if (cfg->ping_num < cfg->ping_max)
return true; /* skip this try */
/* max empty calls reached, make real ping */
cfg->ping_num = 0;
/* TODO */ /* TODO */
return false; return false;

Loading…
Cancel
Save