-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.c
46 lines (40 loc) · 818 Bytes
/
queue.c
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
#include "queue.h"
#include "multi_threaded_server.h"
node_t *head = NULL;
node_t *tail = NULL;
void enqueue(request *client_socket)
{
node_t *newnode = malloc(sizeof(node_t));
newnode->client_socket = client_socket;
newnode->next = NULL;
if (tail == NULL)
{
head = newnode;
}
else
{
tail->next = newnode;
}
tail = newnode;
}
//returns NULL if the queue is the empty
//returns the pointer to the clien_socket, if there is one to get
request *dequeue()
{
if (head == NULL)
{
return NULL;
}
else
{
request *first_node = head->client_socket;
node_t *temp = head;
head = head->next;
if (head == NULL)
{
tail = NULL;
}
free(temp);
return first_node;
}
}