aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2020-02-17 16:34:49 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2020-02-17 16:47:41 +0200
commitf3f2375e0d8636377994da045ca6ab6aaa51e3f0 (patch)
tree4ca53272c03a475408e5e105015f0d48f1534422
parent0dfd07ad3ef44ebc5a1b5118ce66f668768d14a6 (diff)
downloadping903-f3f2375e0d8636377994da045ca6ab6aaa51e3f0.tar.gz
ping903-f3f2375e0d8636377994da045ca6ab6aaa51e3f0.tar.bz2
Fix sporadically occurring ENOBUFS errors after sendto
* src/pinger.c (p903_sender): Call send_echo only if the descriptor is ready for writing.
-rw-r--r--src/pinger.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/pinger.c b/src/pinger.c
index b722fcf..6ebf608 100644
--- a/src/pinger.c
+++ b/src/pinger.c
@@ -31,6 +31,7 @@
#include <errno.h>
#include <pthread.h>
#include <limits.h>
+#include <poll.h>
#include "ping903.h"
#include "json.h"
#include "defs.h"
@@ -277,9 +278,12 @@ send_echo(HOSTADDR *host, unsigned char *ping_buffer)
n = sendto(ping_fd, (char *) ping_buffer, buflen, 0,
host->addr, host->addrlen);
- if (n < 0)
+ if (n < 0) {
error("%s: sendto: %s", host->name, strerror(errno));
- else {
+ if (errno == EINTR || errno == ENOBUFS) {
+ sendq_enqueue(host);
+ }
+ } else {
if (host->xmit_count == 0)
host->start_tv = host->xmit_tv;
host->xmit_count++;
@@ -293,11 +297,23 @@ void *
p903_sender(void *p)
{
unsigned char *ping_buffer;
+ struct pollfd pfd;
+ int n;
+
+ pfd.fd = ping_fd;
+ pfd.events = POLLOUT;
+
ping_buffer = emalloc(sizeof(struct icmp) + data_length);
while (1) {
- HOSTADDR *host = sendq_dequeue();
- send_echo(host, ping_buffer);
+ n = poll(&pfd, 1, 0);
+ if (n == 1) {
+ HOSTADDR *host = sendq_dequeue();
+ send_echo(host, ping_buffer);
+ } else if (n == -1) {
+ fatal("poll: %s", strerror(errno));
+ exit(1);
+ }
}
return NULL;
}

Return to:

Send suggestions and report system problems to the System administrator.