private-lib-system-smd.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * lws System Message Distribution
  3. *
  4. * Copyright (C) 2019 - 2020 Andy Green <[email protected]>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to
  8. * deal in the Software without restriction, including without limitation the
  9. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. * sell copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  22. * IN THE SOFTWARE.
  23. */
  24. /*
  25. * Number of seconds registered peers must remain as zombies to handle in-flight
  26. * older messages correctly
  27. */
  28. #if !defined(LWS_SMD_INFLIGHT_GRACE_SECS)
  29. #define LWS_SMD_INFLIGHT_GRACE_SECS (2)
  30. #endif
  31. #if !defined(LWS_SMD_MAX_QUEUE_DEPTH)
  32. #define LWS_SMD_MAX_QUEUE_DEPTH (12)
  33. #endif
  34. #if defined(LWS_WITH_SECURE_STREAMS)
  35. #define LWS_SMD_SS_RX_HEADER_LEN_EFF (LWS_SMD_SS_RX_HEADER_LEN)
  36. #else
  37. #define LWS_SMD_SS_RX_HEADER_LEN_EFF (0)
  38. #endif
  39. typedef struct lws_smd_msg {
  40. lws_dll2_t list;
  41. lws_usec_t timestamp;
  42. lws_smd_class_t _class;
  43. uint16_t length;
  44. uint16_t refcount;
  45. /* message itself is over-allocated after this */
  46. } lws_smd_msg_t;
  47. /*
  48. * The peer's relationship to the lws instance doing the distribution
  49. */
  50. typedef enum {
  51. LSMDT_SAME_PROCESS, /* we call him back ourselves */
  52. LSMDT_SECURE_STREAMS_LOCAL, /* we call him back ourselves */
  53. LSMDT_SECURE_STREAMS_PROXIED, /* we ask to write and wait */
  54. } lws_smd_type_t;
  55. typedef struct lws_smd_peer {
  56. lws_dll2_t list;
  57. lws_usec_t timestamp_joined;
  58. lws_usec_t timestamp_left;
  59. #if defined(LWS_WITH_SECURE_STREAMS)
  60. lws_ss_handle_t *ss_handle; /* LSMDT_SECURE_STREAMS */
  61. #endif
  62. lws_smd_notification_cb_t cb; /* LSMDT_<other> */
  63. void *opaque;
  64. /* NULL, or next message we will handle */
  65. lws_smd_msg_t *tail;
  66. lws_smd_class_t _class_filter;
  67. lws_smd_type_t type;
  68. } lws_smd_peer_t;
  69. /*
  70. * Manages message distribution
  71. *
  72. * There is one of these in the lws_context, but the distribution action also
  73. * gets involved in delivering to pt event loops individually for SMP case
  74. */
  75. typedef struct lws_smd {
  76. lws_dll2_owner_t owner_messages; /* lws_smd_msg_t */
  77. lws_mutex_t lock_messages;
  78. lws_dll2_owner_t owner_peers; /* lws_smd_peer_t */
  79. lws_mutex_t lock_peers;
  80. /* union of peer class filters, suppress creation of msg classes not set */
  81. lws_smd_class_t _class_filter;
  82. lws_sorted_usec_list_t sul_tail_stale;
  83. char delivering;
  84. } lws_smd_t;
  85. /* check if this tsi has pending messages to deliver */
  86. int
  87. lws_smd_message_pending(struct lws_context *ctx);
  88. int
  89. lws_smd_msg_distribute(struct lws_context *ctx);
  90. int
  91. _lws_smd_destroy(struct lws_context *ctx);