summaryrefslogtreecommitdiff
path: root/src/joblist.c
blob: 7c2102478a01dd96502ea42ef58e0100964f6b27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "first.h"

#include "base.h"
#include "joblist.h"

#include <stdlib.h>
#include <string.h>

int joblist_append(server *srv, connection *con) {
	if (srv->joblist->size == 0) {
		srv->joblist->size  = 16;
		srv->joblist->ptr   = malloc(sizeof(*srv->joblist->ptr) * srv->joblist->size);
		force_assert(NULL != srv->joblist->ptr);
	} else if (srv->joblist->used == srv->joblist->size) {
		srv->joblist->size += 16;
		srv->joblist->ptr   = realloc(srv->joblist->ptr, sizeof(*srv->joblist->ptr) * srv->joblist->size);
		force_assert(NULL != srv->joblist->ptr);
	}

	srv->joblist->ptr[srv->joblist->used++] = con;

	return 0;
}

void joblist_free(server *srv, connections *joblist) {
	UNUSED(srv);

	free(joblist->ptr);
	free(joblist);
}

connection *fdwaitqueue_unshift(server *srv, connections *fdwaitqueue) {
	connection *con;
	UNUSED(srv);


	if (fdwaitqueue->used == 0) return NULL;

	con = fdwaitqueue->ptr[0];

	memmove(fdwaitqueue->ptr, &(fdwaitqueue->ptr[1]), --fdwaitqueue->used * sizeof(*(fdwaitqueue->ptr)));

	return con;
}

int fdwaitqueue_append(server *srv, connection *con) {
	if (srv->fdwaitqueue->size == 0) {
		srv->fdwaitqueue->size  = 16;
		srv->fdwaitqueue->ptr   = malloc(sizeof(*(srv->fdwaitqueue->ptr)) * srv->fdwaitqueue->size);
		force_assert(NULL != srv->fdwaitqueue->ptr);
	} else if (srv->fdwaitqueue->used == srv->fdwaitqueue->size) {
		srv->fdwaitqueue->size += 16;
		srv->fdwaitqueue->ptr   = realloc(srv->fdwaitqueue->ptr, sizeof(*(srv->fdwaitqueue->ptr)) * srv->fdwaitqueue->size);
		force_assert(NULL != srv->fdwaitqueue->ptr);
	}

	srv->fdwaitqueue->ptr[srv->fdwaitqueue->used++] = con;

	return 0;
}

void fdwaitqueue_free(server *srv, connections *fdwaitqueue) {
	UNUSED(srv);
	free(fdwaitqueue->ptr);
	free(fdwaitqueue);
}