svn commit: r224304 - user/hrs/ipv6/usr.sbin/rtadvd
Hiroki Sato
hrs at FreeBSD.org
Mon Jul 25 06:31:31 UTC 2011
Author: hrs
Date: Mon Jul 25 06:31:31 2011
New Revision: 224304
URL: http://svn.freebsd.org/changeset/base/224304
Log:
Use poll() to wait for the control message socket instead of a spin loop.
Modified:
user/hrs/ipv6/usr.sbin/rtadvd/control.c
Modified: user/hrs/ipv6/usr.sbin/rtadvd/control.c
==============================================================================
--- user/hrs/ipv6/usr.sbin/rtadvd/control.c Mon Jul 25 06:31:04 2011 (r224303)
+++ user/hrs/ipv6/usr.sbin/rtadvd/control.c Mon Jul 25 06:31:31 2011 (r224304)
@@ -41,6 +41,7 @@
#include <errno.h>
#include <netdb.h>
#include <unistd.h>
+#include <poll.h>
#include <signal.h>
#include <string.h>
#include <stdarg.h>
@@ -53,12 +54,16 @@
#include "pathnames.h"
#include "control.h"
+#define CMSG_RECV_TIMEOUT 30
+
int
cmsg_recv(int fd, char *buf)
{
int n;
struct ctrl_msg_hdr *cm;
char *msg;
+ struct pollfd pfds[1];
+ int i;
syslog(LOG_DEBUG, "<%s> enter, fd=%d", __func__, fd);
@@ -66,14 +71,31 @@ cmsg_recv(int fd, char *buf)
cm = (struct ctrl_msg_hdr *)buf;
msg = (char *)buf + sizeof(*cm);
+ pfds[0].fd = fd;
+ pfds[0].events = POLLIN;
+
for (;;) {
- n = read(fd, cm, sizeof(*cm));
- if (n < 0 && errno == EAGAIN) {
- syslog(LOG_DEBUG,
- "<%s> waiting...", __func__);
+ i = poll(pfds, sizeof(pfds)/sizeof(pfds[0]),
+ CMSG_RECV_TIMEOUT);
+
+ if (i == 0)
+ continue;
+
+ if (i < 0) {
+ syslog(LOG_ERR, "<%s> poll error: %s",
+ __func__, strerror(errno));
continue;
}
- break;
+
+ if (pfds[0].revents & POLLIN) {
+ n = read(fd, cm, sizeof(*cm));
+ if (n < 0 && errno == EAGAIN) {
+ syslog(LOG_DEBUG,
+ "<%s> waiting...", __func__);
+ continue;
+ }
+ break;
+ }
}
if (n != sizeof(*cm)) {
@@ -109,12 +131,26 @@ cmsg_recv(int fd, char *buf)
msglen);
for (;;) {
- n = read(fd, msg, msglen);
- if (n < 0 && errno == EAGAIN) {
- syslog(LOG_DEBUG,
- "<%s> waiting...", __func__);
+ i = poll(pfds, sizeof(pfds)/sizeof(pfds[0]),
+ CMSG_RECV_TIMEOUT);
+
+ if (i == 0)
+ continue;
+
+ if (i < 0) {
+ syslog(LOG_ERR, "<%s> poll error: %s",
+ __func__, strerror(errno));
continue;
}
+
+ if (pfds[0].revents & POLLIN) {
+ n = read(fd, msg, msglen);
+ if (n < 0 && errno == EAGAIN) {
+ syslog(LOG_DEBUG,
+ "<%s> waiting...", __func__);
+ continue;
+ }
+ }
break;
}
if (n != msglen) {
More information about the svn-src-user
mailing list