summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6784bec)
raw | patch | inline | side by side (parent: 6784bec)
author | Tamás Földesi <tamas.foldesi@more.no> | |
Tue, 30 Jun 2015 17:06:28 +0000 (19:06 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 13 Nov 2015 09:56:57 +0000 (10:56 +0100) |
src/common.c | patch | blob | history |
diff --git a/src/common.c b/src/common.c
index c2849420502846eabcec0c5ab701778275a0bce1..7adbe2ea7dd984e9ade3ad6d7daee2709fcc0cca 100644 (file)
--- a/src/common.c
+++ b/src/common.c
#include <sys/socket.h>
#include <netdb.h>
+#include <poll.h>
+
#if HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
const char *ptr;
size_t nleft;
ssize_t status;
+ struct pollfd pfd;
ptr = (const char *) buf;
nleft = count;
+
+ /* checking for closed peer connection */
+ pfd.fd = fd;
+ pfd.events = POLLIN | POLLHUP | POLLRDNORM;
+ pfd.revents = 0;
+ if (poll(&pfd, 1, 0) > 0) {
+ char buffer[32];
+ if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) {
+ // if recv returns zero (even though poll() said there is data to be read),
+ // that means the connection has been closed
+ return -1;
+ }
+ }
while (nleft > 0)
{