From: Florian Forster Date: Thu, 13 Sep 2012 08:05:35 +0000 (+0200) Subject: apcups plugin: Add function net_shutdown(). X-Git-Tag: collectd-5.0.5~4^2~8 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=3855d8f3a6310d739d35ba9fa86c35d813abf859;p=collectd.git apcups plugin: Add function net_shutdown(). --- diff --git a/src/apcups.c b/src/apcups.c index d6a35c50..60ba7f43 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -81,26 +81,31 @@ static const char *config_keys[] = }; static int config_keys_num = 2; -/* Close the network connection */ -static int apcups_shutdown (void) +static int net_shutdown (int *fd) { uint16_t packet_size = 0; - if (global_sockfd < 0) - return (0); + if ((fd == NULL) || (*fd < 0)) + return (EINVAL); - DEBUG ("Gracefully shutting down socket %i.", global_sockfd); + swrite (*fd, (void *) &packet_size, sizeof (packet_size)); + close (*fd); + *fd = -1; - /* send EOF sentinel */ - swrite (global_sockfd, (void *) &packet_size, sizeof (packet_size)); + return (0); +} /* int net_shutdown */ - close (global_sockfd); - global_sockfd = -1; +/* Close the network connection */ +static int apcups_shutdown (void) +{ + if (global_sockfd < 0) + return (0); + net_shutdown (&global_sockfd); return (0); } /* int apcups_shutdown */ -/* +/* * Open a TCP connection to the UPS network server * Returns -1 on error * Returns socket file descriptor otherwise