1 /* 2 * lws System Message Distribution 3 * 4 * Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com> 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 26 #if defined(LWS_WITH_SECURE_STREAMS) 27 #define LWS_SMD_SS_RX_HEADER_LEN_EFF (LWS_SMD_SS_RX_HEADER_LEN) 28 #else 29 #define LWS_SMD_SS_RX_HEADER_LEN_EFF (0) 30 #endif 31 32 struct lws_smd_peer; 33 34 typedef struct lws_smd_msg { 35 lws_dll2_t list; 36 37 struct lws_smd_peer *exc; 38 39 lws_usec_t timestamp; 40 lws_smd_class_t _class; 41 42 uint16_t length; 43 uint16_t refcount; 44 45 /* message itself is over-allocated after this */ 46 } lws_smd_msg_t; 47 48 typedef struct lws_smd_peer { 49 lws_dll2_t list; 50 51 #if defined(LWS_WITH_SECURE_STREAMS) 52 lws_ss_handle_t *ss_handle; /* LSMDT_SECURE_STREAMS */ 53 #endif 54 55 lws_smd_notification_cb_t cb; /* LSMDT_<other> */ 56 struct lws_context *ctx; 57 void *opaque; 58 59 /* NULL, or next message we will handle */ 60 lws_smd_msg_t *tail; 61 62 lws_smd_class_t _class_filter; 63 } lws_smd_peer_t; 64 65 /* 66 * Manages message distribution 67 * 68 * There is one of these in the lws_context, but the distribution action also 69 * gets involved in delivering to pt event loops individually for SMP case 70 */ 71 72 typedef struct lws_smd { 73 lws_dll2_owner_t owner_messages; /* lws_smd_msg_t */ 74 lws_mutex_t lock_messages; 75 lws_dll2_owner_t owner_peers; /* lws_smd_peer_t */ 76 lws_mutex_t lock_peers; 77 78 /* union of peer class filters, suppress creation of msg classes not set */ 79 lws_smd_class_t _class_filter; 80 81 char delivering; 82 } lws_smd_t; 83 84 /* check if this tsi has pending messages to deliver */ 85 86 int 87 lws_smd_message_pending(struct lws_context *ctx); 88 89 int 90 lws_smd_msg_distribute(struct lws_context *ctx); 91 92 int 93 _lws_smd_destroy(struct lws_context *ctx); 94 95