Call perror() before close(), add detail to messages
This commit is contained in:
committed by
Michael Davidsaver
parent
3ea29f581b
commit
bc5d347bb2
@@ -37,7 +37,7 @@ int epicsNtpGetTime(char *ntpIp, struct timespec *now)
|
||||
sockfd = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); // Create a UDP socket.
|
||||
|
||||
if ( sockfd < 0 ) {
|
||||
perror( "epicsNtpGetTime" );
|
||||
perror( "epicsNtpGetTime creating socket" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -51,24 +51,24 @@ int epicsNtpGetTime(char *ntpIp, struct timespec *now)
|
||||
|
||||
// Call up the server using its IP address and port number.
|
||||
if ( connect( sockfd, ( struct sockaddr * ) &serv_addr, sizeof( serv_addr) ) < 0 ) {
|
||||
perror( "epicsNtpGetTime connecting socket" );
|
||||
close( sockfd );
|
||||
perror( "epicsNtpGetTime" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Send it the NTP packet it wants. If n == -1, it failed.
|
||||
n = write( sockfd, ( char* ) &packet, sizeof( ntp_packet ) );
|
||||
if ( n < 0 ) {
|
||||
perror( "epicsNtpGetTime sending NTP request" );
|
||||
close( sockfd );
|
||||
perror( "epicsNtpGetTime" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Wait and receive the packet back from the server. If n == -1, it failed.
|
||||
// Wait and receive the packet back from the server. If n == -1, it failed.
|
||||
n = read( sockfd, ( char* ) &packet, sizeof( ntp_packet ) );
|
||||
if ( n < 0 ) {
|
||||
perror( "epicsNtpGetTime reading NTP reply" );
|
||||
close( sockfd );
|
||||
perror( "epicsNtpGetTime" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user