From 20cc1f6550e971d163fb60b0d0d35e2650d92d6e Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 4 Aug 2014 16:37:00 +0200 Subject: [PATCH] ntp: move debug message after sendmsg() This should reduce the delay before sending the packet when debugging is enabled. --- ntp_io.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ntp_io.c b/ntp_io.c index b77fb79f..aadae446 100644 --- a/ntp_io.c +++ b/ntp_io.c @@ -707,18 +707,14 @@ send_packet(void *packet, int packetlen, NTP_Remote_Address *remote_addr, NTP_Lo } #endif - reconnect = 0; - -try_again: - DEBUG_LOG(LOGF_NtpIO, "Sending to %s:%d from %s fd %d", - UTI_IPToString(&remote_addr->ip_addr), remote_addr->port, - UTI_IPToString(&local_addr->ip_addr), local_addr->sock_fd); - msg.msg_controllen = cmsglen; /* This is apparently required on some systems */ if (!cmsglen) msg.msg_control = NULL; + reconnect = 0; + +try_again: if (sendmsg(local_addr->sock_fd, &msg, 0) < 0) { /* If this is a separate client socket, try to reconnect it (but no more than once) if not connected yet or if it may be bound to an address that @@ -726,12 +722,18 @@ try_again: reconnect = !reconnect && separate_client_sockets && !addrlen && (errno == ENOTCONN || errno == EDESTADDRREQ || errno == EINVAL); - DEBUG_LOG(LOGF_NtpIO, "Could not send to %s:%d : %s", - UTI_IPToString(&remote_addr->ip_addr), remote_addr->port, strerror(errno)); + DEBUG_LOG(LOGF_NtpIO, "Could not send to %s:%d from %s fd %d : %s", + UTI_IPToString(&remote_addr->ip_addr), remote_addr->port, + UTI_IPToString(&local_addr->ip_addr), local_addr->sock_fd, + strerror(errno)); /* Try sending the packet again if reconnect succeeds */ if (reconnect && reconnect_socket(local_addr->sock_fd, remote_addr)) goto try_again; + } else { + DEBUG_LOG(LOGF_NtpIO, "Sent to %s:%d from %s fd %d", + UTI_IPToString(&remote_addr->ip_addr), remote_addr->port, + UTI_IPToString(&local_addr->ip_addr), local_addr->sock_fd); } } -- 2.47.2