-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathqueue.c
131 lines (113 loc) · 3.27 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Boa, an http server
* Copyright (C) 1995 Paul Phillips <[email protected]>
* Some changes Copyright (C) 1997 Jon Nelson <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/* $Id: queue.c,v 1.21 2002/01/21 02:19:16 jnelson Exp $*/
#include "boa.h"
request *request_ready = NULL; /* ready list head */
request *request_block = NULL; /* blocked list head */
request *request_free = NULL; /* free list head */
/*
* Name: block_request
*
* Description: Moves a request from the ready queue to the blocked queue
*/
void block_request(request * req)
{
dequeue(&request_ready, req);
enqueue(&request_block, req);
if (req->buffer_end) {
BOA_FD_SET(req->fd, &block_write_fdset);
} else {
switch (req->status) {
case WRITE:
case PIPE_WRITE:
case DONE:
BOA_FD_SET(req->fd, &block_write_fdset);
break;
case PIPE_READ:
BOA_FD_SET(req->data_fd, &block_read_fdset);
break;
case BODY_WRITE:
BOA_FD_SET(req->post_data_fd, &block_write_fdset);
break;
default:
BOA_FD_SET(req->fd, &block_read_fdset);
break;
}
}
}
/*
* Name: ready_request
*
* Description: Moves a request from the blocked queue to the ready queue
*/
void ready_request(request * req)
{
dequeue(&request_block, req);
enqueue(&request_ready, req);
if (req->buffer_end) {
FD_CLR(req->fd, &block_write_fdset);
} else {
switch (req->status) {
case WRITE:
case PIPE_WRITE:
case DONE:
FD_CLR(req->fd, &block_write_fdset);
break;
case PIPE_READ:
FD_CLR(req->data_fd, &block_read_fdset);
break;
case BODY_WRITE:
FD_CLR(req->post_data_fd, &block_write_fdset);
break;
default:
FD_CLR(req->fd, &block_read_fdset);
}
}
}
/*
* Name: dequeue
*
* Description: Removes a request from its current queue
*/
void dequeue(request ** head, request * req)
{
if (*head == req)
*head = req->next;
if (req->prev)
req->prev->next = req->next;
if (req->next)
req->next->prev = req->prev;
req->next = NULL;
req->prev = NULL;
}
/*
* Name: enqueue
*
* Description: Adds a request to the head of a queue
*/
void enqueue(request ** head, request * req)
{
if (*head)
(*head)->prev = req; /* previous head's prev is us */
req->next = *head; /* our next is previous head */
req->prev = NULL; /* first in list */
*head = req; /* now we are head */
}