PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/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. /* $Id: queue.c,v 1.21.2.4 2005/02/22 14:11:29 jnelson Exp $*/
  22. #include "boa.h"
  23. request *request_ready = NULL; /* ready list head */
  24. request *request_block = NULL; /* blocked list head */
  25. request *request_free = NULL; /* free list head */
  26. /*
  27. * Name: block_request
  28. *
  29. * Description: Moves a request from the ready queue to the blocked queue
  30. */
  31. void block_request(request * req)
  32. {
  33. dequeue(&request_ready, req);
  34. enqueue(&request_block, req);
  35. if (req->buffer_end) {
  36. BOA_FD_SET(req, req->fd, BOA_WRITE);
  37. } else {
  38. switch (req->status) {
  39. case IOSHUFFLE:
  40. #ifndef HAVE_SENDFILE
  41. if (req->buffer_end - req->buffer_start == 0) {
  42. BOA_FD_SET(req, req->data_fd, BOA_READ);
  43. break;
  44. }
  45. #endif
  46. case WRITE:
  47. case PIPE_WRITE:
  48. case DONE:
  49. BOA_FD_SET(req, req->fd, BOA_WRITE);
  50. break;
  51. case PIPE_READ:
  52. BOA_FD_SET(req, req->data_fd, BOA_READ);
  53. break;
  54. case BODY_WRITE:
  55. BOA_FD_SET(req, req->post_data_fd, BOA_WRITE);
  56. break;
  57. default:
  58. BOA_FD_SET(req, req->fd, BOA_READ);
  59. break;
  60. }
  61. }
  62. }
  63. /*
  64. * Name: ready_request
  65. *
  66. * Description: Moves a request from the blocked queue to the ready queue
  67. */
  68. void ready_request(request * req)
  69. {
  70. dequeue(&request_block, req);
  71. enqueue(&request_ready, req);
  72. if (req->buffer_end) {
  73. BOA_FD_CLR(req, req->fd, BOA_WRITE);
  74. } else {
  75. switch (req->status) {
  76. case IOSHUFFLE:
  77. #ifndef HAVE_SENDFILE
  78. if (req->buffer_end - req->buffer_start == 0) {
  79. BOA_FD_CLR(req, req->data_fd, BOA_READ);
  80. break;
  81. }
  82. #endif
  83. case WRITE:
  84. case PIPE_WRITE:
  85. case DONE:
  86. BOA_FD_CLR(req, req->fd, BOA_WRITE);
  87. break;
  88. case PIPE_READ:
  89. BOA_FD_CLR(req, req->data_fd, BOA_READ);
  90. break;
  91. case BODY_WRITE:
  92. BOA_FD_CLR(req, req->post_data_fd, BOA_WRITE);
  93. break;
  94. default:
  95. BOA_FD_CLR(req, req->fd, BOA_READ);
  96. }
  97. }
  98. }
  99. /*
  100. * Name: dequeue
  101. *
  102. * Description: Removes a request from its current queue
  103. */
  104. void dequeue(request ** head, request * req)
  105. {
  106. if (*head == req)
  107. *head = req->next;
  108. if (req->prev)
  109. req->prev->next = req->next;
  110. if (req->next)
  111. req->next->prev = req->prev;
  112. req->next = NULL;
  113. req->prev = NULL;
  114. }
  115. /*
  116. * Name: enqueue
  117. *
  118. * Description: Adds a request to the head of a queue
  119. */
  120. void enqueue(request ** head, request * req)
  121. {
  122. if (*head)
  123. (*head)->prev = req; /* previous head's prev is us */
  124. req->next = *head; /* our next is previous head */
  125. req->prev = NULL; /* first in list */
  126. *head = req; /* now we are head */
  127. }