status.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* shttpd - send status reports from the worker to the control thread
  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. #include <sHT/intrisics.h>
  14. #include "worker.h"
  15. #include <errno.h>
  16. #include <stdint.h>
  17. #include <sys/epoll.h>
  18. #include <sys/socket.h>
  19. enum sHT_status_id {
  20. /* typically about resource usage*/
  21. sHT_STATUS_CHANGE_FLAGS = 0,
  22. };
  23. __attribute__((nonnull (1, 2)))
  24. static void
  25. sHT_sendstatus_flags(struct sHT_worker *worker, struct sHT_task *task, sHT_worker_flags flags)
  26. {
  27. sHT_assert(flags <= 0xffff);
  28. /* If this turns out to benefit from optimisation,
  29. consider letting the type be uint32_t,
  30. while maintaining this byte order. */
  31. const unsigned char msg[4] = {
  32. (sHT_STATUS_CHANGE_FLAGS & 0xff00) >> 8,
  33. (sHT_STATUS_CHANGE_FLAGS & 0x00ff) >> 0,
  34. (flags & 0xff00) >> 8,
  35. (flags & 0x00ff) >> 0,
  36. };
  37. int ret;
  38. do ret = send(task->fd, msg, sizeof(msg), MSG_DONTWAIT | MSG_NOSIGNAL);
  39. while (ret)
  40. }
  41. void
  42. sHT_sendstatus_task(struct sHT_worker *worker, struct sHT_task *task)
  43. {
  44. if (!(task->epollflags & EPOLLOUT))
  45. return;
  46. if (worker->flags)
  47. sHT_sendstatus_flags(worker, task, worker->flags)
  48. }