/boa-0.94.14rc21/src/queue.c
C | 145 lines | 86 code | 18 blank | 41 comment | 15 complexity | d626e475ad3cac0bd01850fcd1104320 MD5 | raw file
Possible License(s): GPL-2.0
1/*
2 * Boa, an http server
3 * Copyright (C) 1995 Paul Phillips <paulp@go2net.com>
4 * Copyright (C) 1997-2002 Jon Nelson <jnelson@boa.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 1, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 */
21
22/* $Id: queue.c,v 1.21.2.4 2005/02/22 14:11:29 jnelson Exp $*/
23
24#include "boa.h"
25
26request *request_ready = NULL; /* ready list head */
27request *request_block = NULL; /* blocked list head */
28request *request_free = NULL; /* free list head */
29
30/*
31 * Name: block_request
32 *
33 * Description: Moves a request from the ready queue to the blocked queue
34 */
35
36void block_request(request * req)
37{
38 dequeue(&request_ready, req);
39 enqueue(&request_block, req);
40
41 if (req->buffer_end) {
42 BOA_FD_SET(req, req->fd, BOA_WRITE);
43 } else {
44 switch (req->status) {
45 case IOSHUFFLE:
46#ifndef HAVE_SENDFILE
47 if (req->buffer_end - req->buffer_start == 0) {
48 BOA_FD_SET(req, req->data_fd, BOA_READ);
49 break;
50 }
51#endif
52 case WRITE:
53 case PIPE_WRITE:
54 case DONE:
55 BOA_FD_SET(req, req->fd, BOA_WRITE);
56 break;
57 case PIPE_READ:
58 BOA_FD_SET(req, req->data_fd, BOA_READ);
59 break;
60 case BODY_WRITE:
61 BOA_FD_SET(req, req->post_data_fd, BOA_WRITE);
62 break;
63 default:
64 BOA_FD_SET(req, req->fd, BOA_READ);
65 break;
66 }
67 }
68}
69
70/*
71 * Name: ready_request
72 *
73 * Description: Moves a request from the blocked queue to the ready queue
74 */
75
76void ready_request(request * req)
77{
78 dequeue(&request_block, req);
79 enqueue(&request_ready, req);
80
81 if (req->buffer_end) {
82 BOA_FD_CLR(req, req->fd, BOA_WRITE);
83 } else {
84 switch (req->status) {
85 case IOSHUFFLE:
86#ifndef HAVE_SENDFILE
87 if (req->buffer_end - req->buffer_start == 0) {
88 BOA_FD_CLR(req, req->data_fd, BOA_READ);
89 break;
90 }
91#endif
92 case WRITE:
93 case PIPE_WRITE:
94 case DONE:
95 BOA_FD_CLR(req, req->fd, BOA_WRITE);
96 break;
97 case PIPE_READ:
98 BOA_FD_CLR(req, req->data_fd, BOA_READ);
99 break;
100 case BODY_WRITE:
101 BOA_FD_CLR(req, req->post_data_fd, BOA_WRITE);
102 break;
103 default:
104 BOA_FD_CLR(req, req->fd, BOA_READ);
105 }
106 }
107}
108
109
110/*
111 * Name: dequeue
112 *
113 * Description: Removes a request from its current queue
114 */
115
116void dequeue(request ** head, request * req)
117{
118 if (*head == req)
119 *head = req->next;
120
121 if (req->prev)
122 req->prev->next = req->next;
123 if (req->next)
124 req->next->prev = req->prev;
125
126 req->next = NULL;
127 req->prev = NULL;
128}
129
130/*
131 * Name: enqueue
132 *
133 * Description: Adds a request to the head of a queue
134 */
135
136void enqueue(request ** head, request * req)
137{
138 if (*head)
139 (*head)->prev = req; /* previous head's prev is us */
140
141 req->next = *head; /* our next is previous head */
142 req->prev = NULL; /* first in list */
143
144 *head = req; /* now we are head */
145}