accept.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* shttpd - TCP/IP listening sockets associated with tasks
  2. Copyright (C) 2018 Ariadne Devos
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #ifndef _sHT_ACCEPT_H
  14. #define _sHT_ACCEPT_H
  15. #include <sHT/task.h>
  16. struct sHT_worker;
  17. struct sHT_task_stream;
  18. /* A TCP/IP listening socket */
  19. struct sHT_passive
  20. {
  21. int fd;
  22. int max_accept_iterations;
  23. };
  24. struct sHT_task_accept
  25. {
  26. struct sHT_task task;
  27. struct sHT_passive accept;
  28. };
  29. /* Allocate a task for a connection that might be returned by
  30. accept(2). NULL is considered to be an allocation failure.
  31. It is up to this function to set worker->flags error flags. */
  32. __attribute__((warn_unused_result))
  33. __attribute__((nonnull (1, 2)))
  34. struct sHT_task_stream *
  35. sHT_accept_subtask(struct sHT_worker *worker, struct sHT_task_accept *task);
  36. /* subtask has been allocated by sHT_accept_subtask, with the listening socket
  37. being task, but no connection has been accepted by accept(2). Free subtask.
  38. */
  39. __attribute__((nonnull (1, 2, 3)))
  40. void
  41. sHT_accept_abort(struct sHT_worker *worker, struct sHT_task_accept *task, struct sHT_task_stream *subtask);
  42. /* child->stream.fd is set. task can choose what to do with it. task is not
  43. automatically scheduled in case of possible IO. child has been allocated by
  44. sHT_accept_subtask. */
  45. __attribute__((nonnull (1, 2, 3)))
  46. void
  47. sHT_accept_logic(struct sHT_worker *worker, struct sHT_task_accept *task, struct sHT_task_stream *child);
  48. __attribute__((nonnull (1, 2)))
  49. void
  50. sHT_accept_task(struct sHT_worker *worker, struct sHT_task_accept *task);
  51. #endif