summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 31601e4)
raw | patch | inline | side by side (parent: 31601e4)
author | Florian Forster <octo@collectd.org> | |
Thu, 13 Sep 2012 08:05:35 +0000 (10:05 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Thu, 13 Sep 2012 08:19:10 +0000 (10:19 +0200) |
src/apcups.c | patch | blob | history |
diff --git a/src/apcups.c b/src/apcups.c
index d6a35c50929842f04b0641164e06a9127d4c9492..60ba7f4348e6c756f722ff29f074e74c73fabd3e 100644 (file)
--- a/src/apcups.c
+++ b/src/apcups.c
};
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