/[hydra]/hydra/src/queue.c
ViewVC logotype

Contents of /hydra/src/queue.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Sat Sep 21 13:53:23 2002 UTC (21 years, 6 months ago) by nmav
Branch: MAIN
Branch point for: boas
File MIME type: text/plain
Initial revision

1 /*
2 * Boa, an http server
3 * Copyright (C) 1995 Paul Phillips <paulp@go2net.com>
4 * Some changes Copyright (C) 1997 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 2002/01/21 02:19:16 jnelson Exp $*/
23
24 #include "boa.h"
25
26 /*
27 * Name: block_request
28 *
29 * Description: Moves a request from the ready queue to the blocked queue
30 */
31
32 void block_request(server_params* params, request * req)
33 {
34 dequeue(&params->request_ready, req);
35 enqueue(&params->request_block, req);
36
37 if (req->buffer_end) {
38 BOA_FD_SET(req->fd, &params->block_write_fdset);
39 } else {
40 switch (req->status) {
41 case WRITE:
42 case PIPE_WRITE:
43 case DONE:
44 BOA_FD_SET(req->fd, &params->block_write_fdset);
45 break;
46 case PIPE_READ:
47 BOA_FD_SET(req->data_fd, &params->block_read_fdset);
48 break;
49 case BODY_WRITE:
50 BOA_FD_SET(req->post_data_fd, &params->block_write_fdset);
51 break;
52 default:
53 BOA_FD_SET(req->fd, &params->block_read_fdset);
54 break;
55 }
56 }
57 }
58
59 /*
60 * Name: ready_request
61 *
62 * Description: Moves a request from the blocked queue to the ready queue
63 */
64
65 void ready_request(server_params* params, request * req)
66 {
67 dequeue(&params->request_block, req);
68 enqueue(&params->request_ready, req);
69
70 if (req->buffer_end) {
71 FD_CLR(req->fd, &params->block_write_fdset);
72 } else {
73 switch (req->status) {
74 case WRITE:
75 case PIPE_WRITE:
76 case DONE:
77 FD_CLR(req->fd, &params->block_write_fdset);
78 break;
79 case PIPE_READ:
80 FD_CLR(req->data_fd, &params->block_read_fdset);
81 break;
82 case BODY_WRITE:
83 FD_CLR(req->post_data_fd, &params->block_write_fdset);
84 break;
85 default:
86 FD_CLR(req->fd, &params->block_read_fdset);
87 }
88 }
89 }
90
91
92 /*
93 * Name: dequeue
94 *
95 * Description: Removes a request from its current queue
96 */
97
98 void dequeue(request ** head, request * req)
99 {
100 if (*head == req)
101 *head = req->next;
102
103 if (req->prev)
104 req->prev->next = req->next;
105 if (req->next)
106 req->next->prev = req->prev;
107
108 req->next = NULL;
109 req->prev = NULL;
110 }
111
112 /*
113 * Name: enqueue
114 *
115 * Description: Adds a request to the head of a queue
116 */
117
118 void enqueue(request ** head, request * req)
119 {
120 if (*head)
121 (*head)->prev = req; /* previous head's prev is us */
122
123 req->next = *head; /* our next is previous head */
124 req->prev = NULL; /* first in list */
125
126 *head = req; /* now we are head */
127 }
128

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26