perform.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #if 0
  2. /* shttpd http - react to readyness and completeness
  3. Copyright (C) 2018 Ariadne Devos
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include <sHT/intrisics.h>
  15. #include "worker.h"
  16. #include <errno.h>
  17. #include <stddef.h>
  18. #include <sys/epoll.h>
  19. #include <sys/socket.h>
  20. __attribute__((nonnull (1, 2)))
  21. static void
  22. sHT_other_task(struct sHT_worker *worker, struct sHT_task *task)
  23. {
  24. sHT_assert(0);
  25. }
  26. __attribute__((nonnull (1, 2)))
  27. static void
  28. sHT_aio_task(struct sHT_worker *worker, struct sHT_task *task)
  29. {
  30. sHT_assert(0);
  31. }
  32. void
  33. sHT_sendstatus_task(struct sHT_worker *worker, struct sHT_task *task)
  34. {
  35. sHT_assert(0);
  36. }
  37. /* The idea of calling read, write, recv, send, accept ... ourselves is that
  38. the worker's variable code (i.e. specialised code for TLS, HTTP, a prime
  39. sieve ...) is somewhat independent of the socket interfaces of the kernel.
  40. The worker can, however, still do this by itself using sHT_TASK_NOTHING.
  41. TODO: This allows us to treat intra-machine communication specially, e.g.
  42. with shared memory. (Note: this would require memory_order_relaxed or
  43. volatile.)
  44. */
  45. void
  46. sHT_perform_task(struct sHT_worker *worker, struct sHT_task *task)
  47. {
  48. /* The C compiler probably knows better than me how this should be
  49. compiled (e.g. with a jump table). */
  50. switch((enum sHT_task_type) (task->flags & sHT_TASK_TYPE_MASK)) {
  51. case sHT_TASK_T_DIY:
  52. sHT_other_task(worker, task);
  53. break;
  54. case sHT_TASK_T_SOCKET_STREAM:
  55. sHT_socket_task(worker, task);
  56. break;
  57. case sHT_TASK_T_ASYNC_IO:
  58. sHT_aio_task(worker, task);
  59. break;
  60. case sHT_TASK_T_ACCEPT:
  61. sHT_accept_task(worker, task);
  62. break;
  63. case sHT_TASK_T_SENDSTATUS:
  64. sHT_sendstatus_task(worker, task);
  65. break;
  66. default:
  67. sHT_assert(0 && task->flags);
  68. }
  69. }
  70. #endif