summaryrefslogtreecommitdiff
path: root/contrib/ntp/ntpd/ntp_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ntp/ntpd/ntp_io.c')
-rw-r--r--contrib/ntp/ntpd/ntp_io.c46
1 files changed, 18 insertions, 28 deletions
diff --git a/contrib/ntp/ntpd/ntp_io.c b/contrib/ntp/ntpd/ntp_io.c
index e9202491fe7d..6ab7d267d8a2 100644
--- a/contrib/ntp/ntpd/ntp_io.c
+++ b/contrib/ntp/ntpd/ntp_io.c
@@ -19,6 +19,12 @@
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
+#ifdef HAVE_NETINET_IN_SYSTM_H
+# include <netinet/in_systm.h>
+#else /* Some old linux systems at least have in_system.h instead. */
+# include <netinet/in_system.h>
+#endif /* HAVE_NETINET_IN_SYSTM_H */
+#include <netinet/ip.h>
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
@@ -880,7 +886,7 @@ open_socket(
int turn_off_reuse
)
{
- int fd;
+ int fd, tos;
int on = 1, off = 0;
/* create a datagram (UDP) socket */
@@ -905,6 +911,15 @@ open_socket(
msyslog(LOG_ERR, "setsockopt SO_REUSEADDR on fails: %m");
}
+#if defined(IPTOS_LOWDELAY) && defined(IPPROTO_IP) && defined(IP_TOS)
+ /* set IP_TOS to minimize packet delay */
+ tos = IPTOS_LOWDELAY;
+ if (setsockopt(fd, IPPROTO_IP, IP_TOS, (char *) &tos, sizeof(tos)) < 0)
+ {
+ msyslog(LOG_ERR, "setsockopt IPTOS_LOWDELAY on fails: %m");
+ }
+#endif /* IPTOS_LOWDELAY && IPPROTO_IP && IP_TOS */
+
/*
* bind the local address.
*/
@@ -1326,11 +1341,7 @@ input_handler(
{
char buf[RX_BUFF_SIZE];
-#ifndef SYS_WINNT
(void) read(fd, buf, sizeof buf);
-#else
- (void) ReadFile((HANDLE)fd, buf, (DWORD)sizeof buf, NULL, NULL);
-#endif /* SYS_WINNT */
packets_dropped++;
goto select_again;
}
@@ -1340,14 +1351,8 @@ input_handler(
i = (rp->datalen == 0
|| rp->datalen > sizeof(rb->recv_space))
? sizeof(rb->recv_space) : rp->datalen;
-#ifndef SYS_WINNT
rb->recv_length =
- read(fd, (char *)&rb->recv_space, (unsigned)i)
-#else /* SYS_WINNT */
- ReadFile((HANDLE)fd, (char *)&rb->recv_space, (DWORD)i,
- (LPDWORD)&(rb->recv_length), NULL)
-#endif /* SYS_WINNT */
- ;
+ read(fd, (char *)&rb->recv_space, (unsigned)i);
if (rb->recv_length == -1)
{
@@ -1546,35 +1551,20 @@ input_handler(
}
else if (n == -1)
{
-#ifndef SYS_WINNT
int err = errno;
-#else
- DWORD err = WSAGetLastError();
-#endif /* SYS_WINNT */
/*
* extended FAU debugging output
*/
msyslog(LOG_ERR, "select(%d, %s, 0L, 0L, &0.000000) error: %m",
maxactivefd+1, fdbits(maxactivefd, &activefds));
- if (
-#ifndef SYS_WINNT
- (err == EBADF)
-#else
- (err == WSAEBADF)
-#endif /* SYS_WINNT */
- )
- {
+ if (err == EBADF) {
int j, b;
fds = activefds;
for (j = 0; j <= maxactivefd; j++)
if (
-#ifndef SYS_WINNT
(FD_ISSET(j, &fds) && (read(j, &b, 0) == -1))
-#else
- (FD_ISSET(j, &fds) && (!ReadFile((HANDLE)j, &b, 0, NULL, NULL)))
-#endif /* SYS_WINNT */
)
msyslog(LOG_ERR, "Bad file descriptor %d", j);
}