From 61cc5c1939ee910bbbc7bba82682f5ee3a722860 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Sun, 27 Aug 2017 00:05:36 +0200 Subject: [PATCH] Add remove ap thread --- src/include/datastorage.h | 1 + src/main.c | 3 +++ src/storage/datastorage.c | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 3abc942..d86f745 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -91,6 +91,7 @@ pthread_mutex_t ap_array_mutex; ap insert_to_ap_array(ap entry); void print_ap_array(); +void *remove_ap_array_thread(void *arg); // Array #define ARRAY_CLIENT_LEN 1000 diff --git a/src/main.c b/src/main.c index 194a702..316373c 100644 --- a/src/main.c +++ b/src/main.c @@ -98,6 +98,9 @@ int main(int argc, char **argv) { pthread_t tid_kick_clients; pthread_create(&tid_kick_clients, NULL, &kick_clients_thread, NULL); + pthread_t tid_ap; + pthread_create(&tid_ap, NULL, &remove_ap_array_thread, NULL); + //pthread_create(&tid, NULL, &remove_thread, NULL); dawn_init_ubus(ubus_socket, opt_hostapd_dir); diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 20f0ee3..0e76f13 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -28,6 +28,8 @@ void ap_array_insert(ap entry); ap ap_array_delete(ap entry); +void remove_old_ap_entries(time_t current_time, long long int threshold); + void print_ap_entry(ap entry); int probe_entry_last = -1; @@ -425,6 +427,14 @@ void remove_old_probe_entries(time_t current_time, long long int threshold) { } } +void remove_old_ap_entries(time_t current_time, long long int threshold) { + for (int i = 0; i < probe_entry_last; i++) { + if (ap_array[i].time < current_time - threshold) { + ap_array_delete(ap_array[i]); + } + } +} + void *remove_array_thread(void *arg) { while (1) { sleep(TIME_THRESHOLD); @@ -447,6 +457,16 @@ void *remove_client_array_thread(void *arg) { return 0; } +void *remove_ap_array_thread(void *arg) { + while (1) { + sleep(TIME_THRESHOLD_AP); + pthread_mutex_lock(&ap_array_mutex); + printf("[Thread] : Removing old ap entries!\n"); + remove_old_ap_entries(time(0), TIME_THRESHOLD_AP); + pthread_mutex_unlock(&ap_array_mutex); + } + return 0; +} void insert_client_to_array(client entry) { pthread_mutex_lock(&client_array_mutex);