From: octo Date: Sun, 29 Jan 2006 16:40:25 +0000 (+0000) Subject: Fixed problems with the new `network.c' code: X-Git-Tag: collectd-3.7.0~13 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=35e5e3a04fd24827118b06e8ef740fefc030af07;p=collectd.git Fixed problems with the new `network.c' code: - The client only uses one `addrinfo' address, so messages are not send twice.. The default IPv6 multicast address is prefered over the default IPv4 multicast address. - `network_receive' is now interruptible by signals. It returns without error (and without data). - Removed the (old) `Server' and `Port' options from `configfile.c' in favor of the (new) `cf_callback_socket'. --- diff --git a/src/configfile.c b/src/configfile.c index 2569b4a9..c217724a 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -69,13 +69,15 @@ typedef struct cf_mode_item */ static cf_mode_item_t cf_mode_list[] = { + /* {"Server", NULL, MODE_CLIENT }, {"Port", NULL, MODE_CLIENT | MODE_SERVER }, + */ {"PIDFile", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL}, {"DataDir", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL}, {"LogFile", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL} }; -static int cf_mode_num = 5; +static int cf_mode_num = 3; static int nesting_depth = 0; static char *current_module = NULL; diff --git a/src/network.c b/src/network.c index b86d5a25..ddc36e77 100644 --- a/src/network.c +++ b/src/network.c @@ -251,10 +251,14 @@ static int network_connect_default (void) ret = 0; - if (network_create_socket (NET_DEFAULT_V4_ADDR, NET_DEFAULT_PORT) > 0) + if (network_create_socket (NET_DEFAULT_V6_ADDR, NET_DEFAULT_PORT) > 0) ret++; - if (network_create_socket (NET_DEFAULT_V6_ADDR, NET_DEFAULT_PORT) > 0) + /* Don't use IPv4 and IPv6 in parallel by default.. */ + if ((operating_mode == MODE_CLIENT) && (ret != 0)) + return (ret); + + if (network_create_socket (NET_DEFAULT_V4_ADDR, NET_DEFAULT_PORT) > 0) ret++; if (ret == 0) @@ -275,38 +279,32 @@ static int network_get_listen_socket (void) if (socklist_head == NULL) network_connect_default (); - while (1) + FD_ZERO (&readfds); + max_fd = -1; + for (se = socklist_head; se != NULL; se = se->next) { - FD_ZERO (&readfds); - max_fd = -1; - for (se = socklist_head; se != NULL; se = se->next) - { - if (se->mode != operating_mode) - continue; + if (se->mode != operating_mode) + continue; - FD_SET (se->fd, &readfds); - if (se->fd >= max_fd) - max_fd = se->fd + 1; - } + FD_SET (se->fd, &readfds); + if (se->fd >= max_fd) + max_fd = se->fd + 1; + } - if (max_fd == -1) - { - syslog (LOG_WARNING, "No listen sockets found!"); - return (-1); - } + if (max_fd == -1) + { + syslog (LOG_WARNING, "No listen sockets found!"); + return (-1); + } - status = select (max_fd, &readfds, NULL, NULL, NULL); + status = select (max_fd, &readfds, NULL, NULL, NULL); - if ((status == -1) && (errno == EINTR)) - continue; - else if (status == -1) - { + if (status == -1) + { + if (errno != EINTR) syslog (LOG_ERR, "select: %s", strerror (errno)); - return (-1); - } - else - break; - } /* while (true) */ + return (-1); + } fd = -1; for (se = socklist_head; se != NULL; se = se->next) @@ -457,6 +455,7 @@ int network_send (char *type, char *inst, char *value) else { syslog (LOG_ERR, "sendto: %s", strerror (errno)); + ret = -1; break; } }