[PATCH 05/10] Use ka_check_deadline() to simplify gpst_mainloop() and esp_mainloop() timers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Daniel Lenski <dlenski at gmail.com>
---
 esp.c                  | 7 ++-----
 gpst.c                 | 4 +---
 mainloop.c             | 2 +-
 openconnect-internal.h | 1 +
 4 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/esp.c b/esp.c
index 7876fd5..6285ff8 100644
--- a/esp.c
+++ b/esp.c
@@ -253,15 +253,12 @@ int esp_mainloop(struct openconnect_info *vpninfo, int *timeout)
 	int ret;
 
 	if (vpninfo->dtls_state == DTLS_SLEEPING) {
-		int when = vpninfo->new_dtls_started + vpninfo->dtls_attempt_period - time(NULL);
-		if (when <= 0 || vpninfo->dtls_need_reconnect) {
+		if (ka_check_deadline(timeout, time(NULL), vpninfo->new_dtls_started + vpninfo->dtls_attempt_period)
+		    || vpninfo->dtls_need_reconnect) {
 			vpn_progress(vpninfo, PRG_DEBUG, _("Send ESP probes\n"));
 			if (vpninfo->proto->udp_send_probes)
 				vpninfo->proto->udp_send_probes(vpninfo);
-			when = vpninfo->dtls_attempt_period;
 		}
-		if (*timeout > when * 1000)
-			*timeout = when * 1000;
 	}
 	if (vpninfo->dtls_fd == -1)
 		return 0;
diff --git a/gpst.c b/gpst.c
index 76f66c1..a82db64 100644
--- a/gpst.c
+++ b/gpst.c
@@ -904,10 +904,8 @@ int gpst_mainloop(struct openconnect_info *vpninfo, int *timeout)
 		return 0;
 	case DTLS_SECRET:
 	case DTLS_SLEEPING:
-		if (time(NULL) < vpninfo->dtls_times.last_rekey + 5) {
+		if (!ka_check_deadline(timeout, time(NULL), vpninfo->dtls_times.last_rekey + 5)) {
 			/* Allow 5 seconds after configuration for ESP to start */
-			if (*timeout > 5000)
-				*timeout = 5000;
 			return 0;
 		} else if (!vpninfo->ssl_times.last_rekey) {
 			/* ... before we switch to HTTPS instead */
diff --git a/mainloop.c b/mainloop.c
index 4124509..fe185fe 100644
--- a/mainloop.c
+++ b/mainloop.c
@@ -315,7 +315,7 @@ int openconnect_mainloop(struct openconnect_info *vpninfo,
 	return ret < 0 ? ret : -EIO;
 }
 
-static int ka_check_deadline(int *timeout, time_t now, time_t due)
+int ka_check_deadline(int *timeout, time_t now, time_t due)
 {
 	if (now >= due)
 		return 1;
diff --git a/openconnect-internal.h b/openconnect-internal.h
index 4b65444..8f77f22 100644
--- a/openconnect-internal.h
+++ b/openconnect-internal.h
@@ -964,6 +964,7 @@ int tun_mainloop(struct openconnect_info *vpninfo, int *timeout);
 int queue_new_packet(struct pkt_q *q, void *buf, int len);
 int keepalive_action(struct keepalive_info *ka, int *timeout);
 int ka_stalled_action(struct keepalive_info *ka, int *timeout);
+int ka_check_deadline(int *timeout, time_t now, time_t due);
 
 /* xml.c */
 ssize_t read_file_into_string(struct openconnect_info *vpninfo, const char *fname,
-- 
2.7.4




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux