fixed tests + bug in linked

This commit is contained in:
overflowerror 2021-04-29 23:01:27 +02:00
parent 67d398dd98
commit 9cfa9ee6ae
4 changed files with 46 additions and 10 deletions

View file

@ -2,6 +2,8 @@
#include <stdlib.h>
#include <pthread.h>
#include <stdio.h>
#include "linked.h"
linkedList_t linked_create() {
@ -228,12 +230,29 @@ void linked_destroy(linkedList_t* list) {
link_t* link = list->first;
link_t** first = &(list->first);
while(link != NULL) {
pthread_mutex_lock(&(link->lock));
link_t* next = link->next;
// no new links can be added, so we can unlock link (next can't be changed)
if (next != NULL) {
pthread_mutex_lock(&(next->lock));
*first = next;
next->prev = NULL;
pthread_mutex_unlock(&(next->lock));
}
// no need to keep, we are going to clear the list anyway
link->next = NULL;
link->unlinked = true;
if (link->inUse == 0) {
linked_free(link);
} else {
pthread_mutex_unlock(&(link->lock));
linked_unlink(link);
}
link = next;
}

View file

@ -8,6 +8,7 @@
#include <poll.h>
#include <fcntl.h>
#include <time.h>
#include <pthread.h>
#include "networking.h"
#include "linked.h"
@ -133,9 +134,25 @@ void testLinkedList() {
checkInt(linked_length(&list), 2, "list length");
if (pthread_mutex_trylock(&(list.lock)) != 0) {
checkBool(false, "list unlocked");
} else {
checkBool(true, "list unlocked");
pthread_mutex_unlock(&(list.lock));
}
link = list.first;
while(link != NULL) {
checkInt(link->inUse, 0, "raw inUse");
if (pthread_mutex_trylock(&(link->lock)) != 0) {
checkBool(false, "raw unlocked");
} else {
checkBool(true, "raw unlocked");
pthread_mutex_unlock(&(link->lock));
}
link = link->next;
}
@ -261,12 +278,12 @@ void testConfig() {
checkInt(config->binds[0]->nrSites, 1, "site no check");
checkInt(config->binds[0]->sites[0]->nrHostnames, 1, "site hostname no check");
checkString(config->binds[0]->sites[0]->hostnames[0], "example.com", "site hostname check");
checkString(config->binds[0]->sites[0]->documentRoot, "/var/www", "site document root check");
checkString(config->binds[0]->sites[0]->documentRoot, "/", "site document root check");
checkInt(config->binds[0]->sites[0]->nrHandlers, 1, "handler no check");
checkString(config->binds[0]->sites[0]->handlers[0]->dir, "/", "handler dir check");
checkInt(config->binds[0]->sites[0]->handlers[0]->type, FILE_HANDLER_NO, "handler type no check");
checkVoid(config->binds[0]->sites[0]->handlers[0]->handler, &fileHandler, "handler ptr check");
checkString(config->binds[0]->sites[0]->handlers[0]->settings.fileSettings.documentRoot, "/var/www", "handler settings root check");
checkString(config->binds[0]->sites[0]->handlers[0]->settings.fileSettings.documentRoot, "/", "handler settings root check");
checkInt(config->binds[0]->sites[0]->handlers[0]->settings.fileSettings.indexfiles.number, 1, "handler settings index no");
checkString(config->binds[0]->sites[0]->handlers[0]->settings.fileSettings.indexfiles.files[0], "index.html", "handler settings index check");
checkString(config->logging.accessLogfile, "access.log", "access log file check");
@ -283,12 +300,12 @@ void testConfig() {
checkInt(config->binds[1]->nrSites, 1, "site no check");
checkInt(config->binds[1]->sites[0]->nrHostnames, 1, "site hostname no check");
checkString(config->binds[1]->sites[0]->hostnames[0], "example.com", "site hostname check");
checkString(config->binds[1]->sites[0]->documentRoot, "/var/www", "site document root check");
checkString(config->binds[1]->sites[0]->documentRoot, "/", "site document root check");
checkInt(config->binds[1]->sites[0]->nrHandlers, 1, "handler no check");
checkString(config->binds[1]->sites[0]->handlers[0]->dir, "/", "handler dir check");
checkInt(config->binds[1]->sites[0]->handlers[0]->type, FILE_HANDLER_NO, "handler type no check");
checkVoid(config->binds[1]->sites[0]->handlers[0]->handler, &fileHandler, "handler ptr check");
checkString(config->binds[1]->sites[0]->handlers[0]->settings.fileSettings.documentRoot, "/var/www", "handler settings root check");
checkString(config->binds[1]->sites[0]->handlers[0]->settings.fileSettings.documentRoot, "/", "handler settings root check");
checkInt(config->binds[1]->sites[0]->handlers[0]->settings.fileSettings.indexfiles.number, 1, "handler settings index no");
checkString(config->binds[1]->sites[0]->handlers[0]->settings.fileSettings.indexfiles.files[0], "index.html", "handler settings index check");
#endif

View file

@ -1,7 +1,7 @@
bind 0.0.0.0:80 {
site {
hostname = example.com
root = /var/www
root = /
handler / {
type = file
index = index.html
@ -15,7 +15,7 @@ bind 0.0.0.0:443 {
}
site {
hostname = example.com
root = /var/www
root = /
handler / {
type = file
index = index.html

View file

@ -1,7 +1,7 @@
bind 0.0.0.0:80 {
site {
hostname = example.com
root = /var/www
root = /
handler / {
type = file
index = index.html