|
From: <wow...@us...> - 2015-07-14 16:16:21
|
Revision: 582
http://sourceforge.net/p/ptpd/code/582
Author: wowczarek
Date: 2015-07-14 16:16:19 +0000 (Tue, 14 Jul 2015)
Log Message:
-----------
Added NTP engine select() EINTR signal handling,
was giving unnecessary errors on some platforms
where timer signal would collide with select()
for NTP.
Modified Paths:
--------------
trunk/src/dep/ntpengine/ntpdcontrol.c
trunk/src/dep/ntpengine/ntpdcontrol.h
Modified: trunk/src/dep/ntpengine/ntpdcontrol.c
===================================================================
--- trunk/src/dep/ntpengine/ntpdcontrol.c 2015-07-09 16:30:41 UTC (rev 581)
+++ trunk/src/dep/ntpengine/ntpdcontrol.c 2015-07-14 16:16:19 UTC (rev 582)
@@ -377,8 +377,8 @@
fd_set fds;
int n;
int pad;
+ int retries = NTP_EINTR_RETRIES;
-
int ntpdc_pktdatasize;
int implcode=(u_char)3;
@@ -414,43 +414,33 @@
tvo = tvsout;
FD_SET(control->sockFD, &fds);
- n = select(control->sockFD+1, &fds, (fd_set *)0, (fd_set *)0, &tvo);
+
+ do {
+ n = select(control->sockFD+1, &fds, (fd_set *)0, (fd_set *)0, &tvo);
+ if( n == -1 && errno == EINTR) {
+ DBG("NTPDCresponse(): EINTR caught\n");
+ retries--;
+ }
+ } while ((n == -1) && retries);
if (n == -1) {
- /* warning("select fails", "", "");*/
+ DBG("NTPDCresponse(): select failed - not EINTR: %s\n", strerror(errno));
return -1;
}
if (n == 0) {
- /*
- * Timed out. Return what we have
- */
+ DBG("NTP response select timeout");
if (firstpkt) {
return ERR_TIMEOUT;
-///timeout?
} else {
-/* (void) fprintf(stderr,
- "%s: timed out with incomplete data\n",
- currenthost);
-*/
-/* if (debug) {
- printf("Received sequence numbers");
- for (n = 0; n <= MAXSEQ; n++)
- if (haveseq[n])
- printf(" %d,", n);
- if (lastseq != 999)
- printf(" last frame received\n");
- else
- printf(" last frame not received\n");
- }
-*/
return ERR_INCOMPLETE;
}
}
n = recv(control->sockFD, (char *)&rpkt, sizeof(rpkt), 0);
+
if (n == -1) {
- /* warning("read", "", "");*/
- return -1;
+ DBG("NTP response recv failed\n");
+ return -1;
}
@@ -458,10 +448,6 @@
* Check for format errors. Bug proofing.
*/
if (n < RESP_HEADER_SIZE) {
-/* if (debug)
- printf("Short (%d byte) packet received\n", n);
-*/
-
goto again;
}
@@ -653,6 +639,7 @@
)
{
int res;
+ int retries = NTP_EINTR_RETRIES;
char junk[512];
fd_set fds;
struct timeval tvzero;
@@ -669,19 +656,24 @@
res = select(control->sockFD+1, &fds, (fd_set *)0, (fd_set *)0, &tvzero);
if (res == -1) {
-// INFO("junk cleanup - select fails");
-// warning("polling select", "", "");
+ if((errno == EINTR) && retries ) {
+ DBG("NTPDCquery(): select EINTR caught");
+ retries--;
+ res = 1;
+ continue;
+ }
+ DBG("NTPDCquery(): select() error - not EINTR: %s\n", strerror(errno));
return -1;
- } else if (res > 0)
-
+ } else if (res > 0) {
(void) recv(control->sockFD, junk, sizeof junk, 0);
+ }
} while (res > 0);
/*
* send a request
*/
res = NTPDCrequest(options, control, reqcode, auth, qitems, qsize, qdata);
- if (res <= 0) {
+ if (res <= 0) {
return res;
}
/*
Modified: trunk/src/dep/ntpengine/ntpdcontrol.h
===================================================================
--- trunk/src/dep/ntpengine/ntpdcontrol.h 2015-07-09 16:30:41 UTC (rev 581)
+++ trunk/src/dep/ntpengine/ntpdcontrol.h 2015-07-14 16:16:19 UTC (rev 582)
@@ -356,4 +356,7 @@
#define INITDATASIZE (sizeof(struct resp_pkt) * 16)
#define INCDATASIZE (sizeof(struct resp_pkt) * 8)
+/* how many time select() will retry on EINTR */
+#define NTP_EINTR_RETRIES 5
+
#endif /* NTPDCONTROL_H */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|