Add remove ap thread

This commit is contained in:
PolynomialDivision 2017-08-27 00:05:36 +02:00
parent 67fcaba74c
commit 61cc5c1939
3 changed files with 24 additions and 0 deletions

View file

@ -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

View file

@ -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);

View file

@ -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);