accept.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. // Copyright © 2018-2019 Ariadne Devos
  3. /* shttpd - TCP/IP listening sockets associated with tasks */
  4. #ifndef _sHT_ACCEPT_H
  5. #define _sHT_ACCEPT_H
  6. #include <sHT/task.h>
  7. struct sHT_worker;
  8. struct sHT_task_stream;
  9. /* A TCP/IP listening socket */
  10. struct sHT_passive
  11. {
  12. int fd;
  13. int max_accept_iterations;
  14. };
  15. struct sHT_task_accept
  16. {
  17. struct sHT_task task;
  18. struct sHT_passive accept;
  19. };
  20. /* Allocate a task for a connection that might be returned by
  21. accept(2). NULL is considered to be an allocation failure.
  22. It is up to this function to set worker->flags error flags. */
  23. __attribute__((warn_unused_result))
  24. __attribute__((nonnull (1, 2)))
  25. struct sHT_task_stream *
  26. sHT_accept_subtask(struct sHT_worker *worker, struct sHT_task_accept *task);
  27. /* subtask has been allocated by sHT_accept_subtask, with the listening socket
  28. being task, but no connection has been accepted by accept(2). Free subtask.
  29. */
  30. __attribute__((nonnull (1, 2, 3)))
  31. void
  32. sHT_accept_abort(struct sHT_worker *worker, struct sHT_task_accept *task, struct sHT_task_stream *subtask);
  33. /* child->stream.fd is set. task can choose what to do with it. task is not
  34. automatically scheduled in case of possible IO. child has been allocated by
  35. sHT_accept_subtask. */
  36. __attribute__((nonnull (1, 2, 3)))
  37. void
  38. sHT_accept_logic(struct sHT_worker *worker, struct sHT_task_accept *task, struct sHT_task_stream *child);
  39. __attribute__((nonnull (1, 2)))
  40. void
  41. sHT_accept_task(struct sHT_worker *worker, struct sHT_task_accept *task);
  42. #endif