add main loop callback and move android arp code to this callback

This commit is contained in:
switch_st 2020-07-21 15:04:16 +08:00
parent 0ab9f3229e
commit 72701a5e83
2 changed files with 6 additions and 13 deletions

View File

@ -114,10 +114,6 @@ typedef struct ether_hdr ether_hdr_t;
#include <zstd.h>
#endif
#ifdef __ANDROID_NDK__
#define ARP_PERIOD_INTERVAL (10) /* sec */
#endif /* #ifdef __ANDROID_NDK__ */
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
@ -239,6 +235,9 @@ typedef struct n2n_edge_callbacks {
/* Called whenever the IP address of the TAP interface changes. */
void (*ip_address_changed)(n2n_edge_t *eee, uint32_t old_ip, uint32_t new_ip);
/* Called periodically in the main loop. */
void (*main_loop_period)(n2n_edge_t *eee, time_t now);
} n2n_edge_callbacks_t;
/* ***************************************************** */

View File

@ -1825,9 +1825,6 @@ int run_edge_loop(n2n_edge_t * eee, int *keep_running) {
time_t lastTransop=0;
time_t last_purge_known = 0;
time_t last_purge_pending = 0;
#ifdef __ANDROID_NDK__
time_t lastArpPeriod=0;
#endif
#ifdef WIN32
struct tunread_arg arg;
@ -1941,12 +1938,9 @@ int run_edge_loop(n2n_edge_t * eee, int *keep_running) {
eee->cb.ip_address_changed(eee, old_ip, eee->device.ip_addr);
}
#ifdef __ANDROID_NDK__
if((nowTime - lastArpPeriod) > ARP_PERIOD_INTERVAL) {
uip_arp_timer();
lastArpPeriod = nowTime;
}
#endif /* #ifdef __ANDROID_NDK__ */
if (eee->cb.main_loop_period)
eee->cb.main_loop_period(eee, nowTime);
} /* while */
#ifdef WIN32