Explorar el Código

【修改】ntp 功能添加超时 errno 判断

Signed-off-by: chenyong <1521761801@qq.com>
chenyong hace 7 años
padre
commit
df1c378b2e
Se han modificado 1 ficheros con 5 adiciones y 2 borrados
  1. 5 2
      ntp/ntp.c

+ 5 - 2
ntp/ntp.c

@@ -27,7 +27,6 @@
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/socket.h>
-#include <sys/select.h>
 #include <netinet/in.h>
 #include <netdb.h>
 
@@ -185,7 +184,11 @@ time_t ntp_get_time(const char *host_name)
     n = recv(sockfd, (char*) &packet, sizeof(ntp_packet), 0);
 
     if (n < 0) {
-        ntp_error("reading from socket, error code %d.", n);
+        if (errno == EWOULDBLOCK || errno == EAGAIN) {
+            ntp_error("receive the socket timeout(%ds)", NTP_GET_TIMEOUT);
+        } else {
+            ntp_error("reading from socket, error code %d.", n);
+        }
         goto __exit;
     }