| 1 | /*! \file janus_nanomsgevh.c |
| 2 | * \author Lorenzo Miniero <[email protected]> |
| 3 | * \copyright GNU General Public License v3 |
| 4 | * \brief Janus NanomsgEventHandler plugin |
| 5 | * \details This is a trivial Nanomsg event handler plugin for Janus |
| 6 | * |
| 7 | * \ingroup eventhandlers |
| 8 | * \ref eventhandlers |
| 9 | */ |
| 10 | |
| 11 | #include "eventhandler.h"cxx . . $ `<file>/src/events/eventhandler.h`/ |
| 12 | |
| 13 | #include <math.h> |
| 14 | |
| 15 | #include <nanomsg/nn.h> |
| 16 | #include <nanomsg/pubsub.h> |
| 17 | #include <nanomsg/inproc.h> |
| 18 | #include <nanomsg/ipc.h> |
| 19 | #include <nanomsg/pipeline.h> |
| 20 | |
| 21 | #include "../debug.h"cxx . . $ `<file>/src/debug.h`/ |
| 22 | #include "../config.h"cxx . . $ `<file>/src/config.h`/ |
| 23 | #include "../utils.h"cxx . . $ `<file>/src/utils.h`/ |
| 24 | #include "../events.h"cxx . . $ `<file>/src/events.h`/ |
| 25 | |
| 26 | |
| 27 | /* Plugin information */ |
| 28 | #define JANUS_NANOMSGEVH_VERSIONcxx . . $ `src/events/janus_nanomsgevh.c:28:9`! 1 |
| 29 | #define JANUS_NANOMSGEVH_VERSION_STRINGcxx . . $ `src/events/janus_nanomsgevh.c:29:9`! "0.0.1" |
| 30 | #define JANUS_NANOMSGEVH_DESCRIPTIONcxx . . $ `src/events/janus_nanomsgevh.c:30:9`! "This is a trivial Nanomsg event handler plugin for Janus." |
| 31 | #define JANUS_NANOMSGEVH_NAMEcxx . . $ `src/events/janus_nanomsgevh.c:31:9`! "JANUS NanomsgEventHandler plugin" |
| 32 | #define JANUS_NANOMSGEVH_AUTHORcxx . . $ `src/events/janus_nanomsgevh.c:32:9`! "Meetecho s.r.l." |
| 33 | #define JANUS_NANOMSGEVH_PACKAGEcxx . . $ `src/events/janus_nanomsgevh.c:33:9`! "janus.eventhandler.nanomsgevh" |
| 34 | |
| 35 | /* Plugin methods */ |
| 36 | janus_eventhandlercxx . . $ janus_eventhandler# *createcxx . . $ create(bc06cdb361c61006).(void); |
| 37 | int janus_nanomsgevh_initcxx . . $ janus_nanomsgevh_init(5c4306d8553b3696).(const char *config_path); |
| 38 | void janus_nanomsgevh_destroycxx . . $ janus_nanomsgevh_destroy(49f6e7a06ebc5aa8).(void); |
| 39 | int janus_nanomsgevh_get_api_compatibilitycxx . . $ janus_nanomsgevh_get_api_compatibility(b126dc7c1de90089).(void); |
| 40 | int janus_nanomsgevh_get_versioncxx . . $ janus_nanomsgevh_get_version(b126dc7c1de90089).(void); |
| 41 | const char *janus_nanomsgevh_get_version_stringcxx . . $ janus_nanomsgevh_get_version_string(33a1f659e94feb42).(void); |
| 42 | const char *janus_nanomsgevh_get_descriptioncxx . . $ janus_nanomsgevh_get_description(33a1f659e94feb42).(void); |
| 43 | const char *janus_nanomsgevh_get_namecxx . . $ janus_nanomsgevh_get_name(33a1f659e94feb42).(void); |
| 44 | const char *janus_nanomsgevh_get_authorcxx . . $ janus_nanomsgevh_get_author(33a1f659e94feb42).(void); |
| 45 | const char *janus_nanomsgevh_get_packagecxx . . $ janus_nanomsgevh_get_package(33a1f659e94feb42).(void); |
| 46 | void janus_nanomsgevh_incoming_eventcxx . . $ janus_nanomsgevh_incoming_event(f530285a7fd488d8).(json_tcxx . . $ json_t# *event); |
| 47 | json_tcxx . . $ json_t# *janus_nanomsgevh_handle_requestcxx . . $ janus_nanomsgevh_handle_request(d6c74909b48cac1f).(json_tcxx . . $ json_t# *request); |
| 48 | |
| 49 | /* Event handler setup */ |
| 50 | static janus_eventhandlercxx . . $ janus_eventhandler# janus_nanomsgevhcxx . . $ janus_nanomsgevh. = |
| 51 | JANUS_EVENTHANDLER_INITcxx . . $ `src/events/eventhandler.h:194:9`! ( |
| 52 | .init = janus_nanomsgevh_init, |
| 53 | .destroy = janus_nanomsgevh_destroy, |
| 54 | |
| 55 | .get_api_compatibility = janus_nanomsgevh_get_api_compatibility, |
| 56 | .get_version = janus_nanomsgevh_get_version, |
| 57 | .get_version_string = janus_nanomsgevh_get_version_string, |
| 58 | .get_description = janus_nanomsgevh_get_description, |
| 59 | .get_name = janus_nanomsgevh_get_name, |
| 60 | .get_author = janus_nanomsgevh_get_author, |
| 61 | .get_package = janus_nanomsgevh_get_package, |
| 62 | |
| 63 | .incoming_event = janus_nanomsgevh_incoming_event, |
| 64 | .handle_request = janus_nanomsgevh_handle_request, |
| 65 | |
| 66 | .events_mask = JANUS_EVENT_TYPE_NONEcxx . . $ `src/events/eventhandler.h:129:9`! |
| 67 | ); |
| 68 | |
| 69 | /* Plugin creator */ |
| 70 | janus_eventhandlercxx . . $ janus_eventhandler# *createcxx . . $ create(bc06cdb361c61006).(void) { |
| 71 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "%s created!\n", JANUS_NANOMSGEVH_NAMEcxx . . $ `src/events/janus_nanomsgevh.c:31:9`!); |
| 72 | return &janus_nanomsgevhcxx . . $ janus_nanomsgevh.; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | /* Useful stuff */ |
| 77 | static volatile gintcxx . . $ gint# initializedcxx . . $ initialized. = 0, stoppingcxx . . $ stopping. = 0; |
| 78 | static GThreadcxx . . $ GThread# *pub_threadcxx . . $ pub_thread., *handler_threadcxx . . $ handler_thread.; |
| 79 | static void *janus_nanomsgevh_threadcxx . . $ janus_nanomsgevh_thread(9f162e79bfc6c74).(void *data); |
| 80 | static void *janus_nanomsgevh_handlercxx . . $ janus_nanomsgevh_handler(9f162e79bfc6c74).(void *data); |
| 81 | |
| 82 | /* Queue of events to handle */ |
| 83 | static GAsyncQueuecxx . . $ GAsyncQueue# *eventscxx . . $ events. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, *nfd_queuecxx . . $ nfd_queue. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 84 | static gbooleancxx . . $ gboolean# group_eventscxx . . $ group_events. = TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 85 | static json_tcxx . . $ json_t# exit_eventcxx . . $ exit_event.; |
| 86 | static void janus_nanomsgevh_event_freecxx . . $ janus_nanomsgevh_event_free(f530285a7fd488d8).(json_tcxx . . $ json_t# *event) { |
| 87 | if(!event || event == &exit_eventcxx . . $ exit_event.) |
| 88 | return; |
| 89 | json_decrefcxx . . $ json_decref(f530285a7fd488d8).(event); |
| 90 | } |
| 91 | |
| 92 | /* JSON serialization options */ |
| 93 | static size_t json_formatcxx . . $ json_format. = JSON_COMPACTcxx . . $ `<external>/8172222224910760005/jansson.h:383:9`! | JSON_PRESERVE_ORDERcxx . . $ `<external>/8172222224910760005/jansson.h:386:9`!; |
| 94 | |
| 95 | /* Nanomsg stuff */ |
| 96 | static int nfdcxx . . $ nfd. = -1, nfd_addrcxx . . $ nfd_addr. = -1, write_nfdcxx . . $ write_nfd.[2]; |
| 97 | |
| 98 | |
| 99 | /* Parameter validation (for tweaking via Admin API) */ |
| 100 | static struct janus_json_parametercxx . . $ janus_json_parameter# request_parameterscxx . . $ request_parameters.[] = { |
| 101 | {"request", JSON_STRINGcxx . . $ JSON_STRING., JANUS_JSON_PARAM_REQUIREDcxx . . $ `src/utils.h:25:9`!} |
| 102 | }; |
| 103 | static struct janus_json_parametercxx . . $ janus_json_parameter# tweak_parameterscxx . . $ tweak_parameters.[] = { |
| 104 | {"events", JSON_STRINGcxx . . $ JSON_STRING., 0}, |
| 105 | {"grouping", JANUS_JSON_BOOLcxx . . $ `src/utils.h:24:9`!, 0} |
| 106 | }; |
| 107 | /* Error codes (for the tweaking via Admin API */ |
| 108 | #define JANUS_NANOMSGEVH_ERROR_INVALID_REQUESTcxx . . $ `src/events/janus_nanomsgevh.c:108:9`! 411 |
| 109 | #define JANUS_NANOMSGEVH_ERROR_MISSING_ELEMENTcxx . . $ `src/events/janus_nanomsgevh.c:109:9`! 412 |
| 110 | #define JANUS_NANOMSGEVH_ERROR_INVALID_ELEMENTcxx . . $ `src/events/janus_nanomsgevh.c:110:9`! 413 |
| 111 | #define JANUS_NANOMSGEVH_ERROR_UNKNOWN_ERRORcxx . . $ `src/events/janus_nanomsgevh.c:111:9`! 499 |
| 112 | |
| 113 | |
| 114 | /* Plugin implementation */ |
| 115 | int janus_nanomsgevh_initcxx . . $ janus_nanomsgevh_init(5c4306d8553b3696).(const char *config_path) { |
| 116 | gbooleancxx . . $ gboolean# success = TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 117 | if(g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&stopping)) { |
| 118 | /* Still stopping from before */ |
| 119 | return -1; |
| 120 | } |
| 121 | if(config_path == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 122 | /* Invalid arguments */ |
| 123 | return -1; |
| 124 | } |
| 125 | /* Read configuration */ |
| 126 | char filename[255]; |
| 127 | g_snprintfcxx . . $ g_snprintf(ea502d73e74c754c).(filename, 255, "%s/%s.jcfg", config_path, JANUS_NANOMSGEVH_PACKAGEcxx . . $ `src/events/janus_nanomsgevh.c:33:9`!); |
| 128 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "Configuration file: %s\n", filename); |
| 129 | janus_configcxx . . $ janus_config# *config = janus_config_parsecxx . . $ janus_config_parse(569dd6a74ea9e7ee).(filename); |
| 130 | if(config == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 131 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_WARNcxx . . $ `src/debug.h:45:9`!, "Couldn't find .jcfg configuration file (%s), trying .cfg\n", JANUS_NANOMSGEVH_PACKAGEcxx . . $ `src/events/janus_nanomsgevh.c:33:9`!); |
| 132 | g_snprintfcxx . . $ g_snprintf(ea502d73e74c754c).(filename, 255, "%s/%s.cfg", config_path, JANUS_NANOMSGEVH_PACKAGEcxx . . $ `src/events/janus_nanomsgevh.c:33:9`!); |
| 133 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "Configuration file: %s\n", filename); |
| 134 | config = janus_config_parsecxx . . $ janus_config_parse(569dd6a74ea9e7ee).(filename); |
| 135 | } |
| 136 | if(config != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 137 | janus_config_printcxx . . $ janus_config_print(95a2b4d96b3e84c9).(config); |
| 138 | janus_config_categorycxx . . $ janus_config_category# *config_general = janus_config_get_createcxx . . $ janus_config_get_create(7f9b951c745e015c).(config, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, janus_config_type_categorycxx . . $ janus_config_type_category., "general"); |
| 139 | |
| 140 | /* Setup the event handler, if required */ |
| 141 | janus_config_itemcxx . . $ janus_config_item# *item = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_general, janus_config_type_itemcxx . . $ janus_config_type_item., "enabled"); |
| 142 | if(!item || !item->valuecxx . . $ janus_config_container#value. || !janus_is_truecxx . . $ janus_is_true(5c4306d8553b3696).(item->valuecxx . . $ janus_config_container#value.)) { |
| 143 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_WARNcxx . . $ `src/debug.h:45:9`!, "Nanomsg event handler disabled\n"); |
| 144 | goto error; |
| 145 | } |
| 146 | |
| 147 | item = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_general, janus_config_type_itemcxx . . $ janus_config_type_item., "json"); |
| 148 | if(item && item->valuecxx . . $ janus_config_container#value.) { |
| 149 | /* Check how we need to format/serialize the JSON output */ |
| 150 | if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(item->valuecxx . . $ janus_config_container#value., "indented")) { |
| 151 | /* Default: indented, we use three spaces for that */ |
| 152 | json_formatcxx . . $ json_format. = JSON_INDENTcxx . . $ `<external>/8172222224910760005/jansson.h:382:9`!(3) | JSON_PRESERVE_ORDERcxx . . $ `<external>/8172222224910760005/jansson.h:386:9`!; |
| 153 | } else if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(item->valuecxx . . $ janus_config_container#value., "plain")) { |
| 154 | /* Not indented and no new lines, but still readable */ |
| 155 | json_formatcxx . . $ json_format. = JSON_INDENTcxx . . $ `<external>/8172222224910760005/jansson.h:382:9`!(0) | JSON_PRESERVE_ORDERcxx . . $ `<external>/8172222224910760005/jansson.h:386:9`!; |
| 156 | } else if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(item->valuecxx . . $ janus_config_container#value., "compact")) { |
| 157 | /* Compact, so no spaces between separators */ |
| 158 | json_formatcxx . . $ json_format. = JSON_COMPACTcxx . . $ `<external>/8172222224910760005/jansson.h:383:9`! | JSON_PRESERVE_ORDERcxx . . $ `<external>/8172222224910760005/jansson.h:386:9`!; |
| 159 | } else { |
| 160 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_WARNcxx . . $ `src/debug.h:45:9`!, "Unsupported JSON format option '%s', using default (compact)\n", item->value); |
| 161 | json_formatcxx . . $ json_format. = JSON_COMPACTcxx . . $ `<external>/8172222224910760005/jansson.h:383:9`! | JSON_PRESERVE_ORDERcxx . . $ `<external>/8172222224910760005/jansson.h:386:9`!; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | /* Which events should we subscribe to? */ |
| 166 | item = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_general, janus_config_type_itemcxx . . $ janus_config_type_item., "events"); |
| 167 | if(item && item->valuecxx . . $ janus_config_container#value.) |
| 168 | janus_events_edit_events_maskcxx . . $ janus_events_edit_events_mask(a076e8a1d44d5614).(item->valuecxx . . $ janus_config_container#value., &janus_nanomsgevhcxx . . $ janus_nanomsgevh..events_maskcxx . . $ janus_eventhandler#events_mask.); |
| 169 | |
| 170 | /* Is grouping of events ok? */ |
| 171 | item = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_general, janus_config_type_itemcxx . . $ janus_config_type_item., "grouping"); |
| 172 | if(item && item->valuecxx . . $ janus_config_container#value.) |
| 173 | group_eventscxx . . $ group_events. = janus_is_truecxx . . $ janus_is_true(5c4306d8553b3696).(item->valuecxx . . $ janus_config_container#value.); |
| 174 | |
| 175 | /* First of all, initialize the pipeline for writeable notifications */ |
| 176 | write_nfdcxx . . $ write_nfd.[0] = nn_socketcxx . . $ nn_socket(9b79fb6aee4c0440).(AF_SPcxx . . $ `<external>/13568548034321366761/nn.h:310:9`!, NN_PULLcxx . . $ `<external>/4028107603240996394/pipeline.h:34:9`!); |
| 177 | write_nfdcxx . . $ write_nfd.[1] = nn_socketcxx . . $ nn_socket(9b79fb6aee4c0440).(AF_SPcxx . . $ `<external>/13568548034321366761/nn.h:310:9`!, NN_PUSHcxx . . $ `<external>/4028107603240996394/pipeline.h:33:9`!); |
| 178 | if(nn_bindcxx . . $ nn_bind(95e580389a7cc305).(write_nfdcxx . . $ write_nfd.[0], "inproc://janusevh") < 0) { |
| 179 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Error configuring internal Nanomsg pipeline... %d (%s)\n", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 180 | goto error; |
| 181 | } |
| 182 | if(nn_connectcxx . . $ nn_connect(95e580389a7cc305).(write_nfdcxx . . $ write_nfd.[1], "inproc://janusevh") < 0) { |
| 183 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Error configuring internal Nanomsg pipeline...%d (%s)\n", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 184 | goto error; |
| 185 | } |
| 186 | /* Handle the Nanomsg configuration */ |
| 187 | item = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_general, janus_config_type_itemcxx . . $ janus_config_type_item., "address"); |
| 188 | const char *address = item && item->valuecxx . . $ janus_config_container#value. ? item->valuecxx . . $ janus_config_container#value. : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 189 | item = janus_config_getcxx . . $ janus_config_get(7f9b951c745e015c).(config, config_general, janus_config_type_itemcxx . . $ janus_config_type_item., "mode"); |
| 190 | const char *mode = item && item->valuecxx . . $ janus_config_container#value. ? item->valuecxx . . $ janus_config_container#value. : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 191 | if(mode == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 192 | mode = "connect"; |
| 193 | nfdcxx . . $ nfd. = nn_socketcxx . . $ nn_socket(9b79fb6aee4c0440).(AF_SPcxx . . $ `<external>/13568548034321366761/nn.h:310:9`!, NN_PUBcxx . . $ `<external>/3733244420840089098/pubsub.h:32:9`!); |
| 194 | if(nfdcxx . . $ nfd. < 0) { |
| 195 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Error creating Nanomsg event handler socket: %d (%s)\n", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 196 | goto error; |
| 197 | } |
| 198 | if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(mode, "bind")) { |
| 199 | /* Bind to this address */ |
| 200 | nfd_addrcxx . . $ nfd_addr. = nn_bindcxx . . $ nn_bind(95e580389a7cc305).(nfdcxx . . $ nfd., address); |
| 201 | if(nfd_addrcxx . . $ nfd_addr. < 0) { |
| 202 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Error binding Nanomsg event handler socket to address '%s': %d (%s)\n", |
| 203 | address, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 204 | goto error; |
| 205 | } |
| 206 | } else if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(mode, "connect")) { |
| 207 | /* Connect to this address */ |
| 208 | nfd_addrcxx . . $ nfd_addr. = nn_connectcxx . . $ nn_connect(95e580389a7cc305).(nfdcxx . . $ nfd., address); |
| 209 | if(nfd_addrcxx . . $ nfd_addr. < 0) { |
| 210 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Error connecting Nanomsg event handler socket to address '%s': %d (%s)\n", |
| 211 | address, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 212 | goto error; |
| 213 | } |
| 214 | } else { |
| 215 | /* Unsupported mode */ |
| 216 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "Unsupported mode '%s'\n", mode); |
| 217 | goto error; |
| 218 | } |
| 219 | |
| 220 | /* Initialize the events queue */ |
| 221 | eventscxx . . $ events. = g_async_queue_new_fullcxx . . $ g_async_queue_new_full(a5bd63b227566187).((GDestroyNotifycxx . . $ GDestroyNotify#) janus_nanomsgevh_event_freecxx . . $ janus_nanomsgevh_event_free(f530285a7fd488d8).); |
| 222 | nfd_queuecxx . . $ nfd_queue. = g_async_queue_new_fullcxx . . $ g_async_queue_new_full(a5bd63b227566187).((GDestroyNotifycxx . . $ GDestroyNotify#) g_freecxx . . $ g_free(5d22bdacc48458e8).); |
| 223 | g_atomic_int_setcxx . . $ `<external>/742587799302188836/gatomic.h:117:9`!(&initialized, 1); |
| 224 | |
| 225 | /* Start the Nanomsg and event handler threads */ |
| 226 | GErrorcxx . . $ GError# *error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 227 | handler_threadcxx . . $ handler_thread. = g_thread_try_newcxx . . $ g_thread_try_new(e63133a8f5fd7576).("janus nanomsgevh thread", janus_nanomsgevh_threadcxx . . $ janus_nanomsgevh_thread(9f162e79bfc6c74)., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &error); |
| 228 | if(error != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 229 | g_atomic_int_setcxx . . $ `<external>/742587799302188836/gatomic.h:117:9`!(&initialized, 0); |
| 230 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_FATALcxx . . $ `src/debug.h:41:9`!, "Got error %d (%s) trying to launch the NanomsgEventHandler loop thread...\n", |
| 231 | error->code, error->message ? error->message : "??"); |
| 232 | g_error_freecxx . . $ g_error_free(2ff7d11a2ecc01bd).(error); |
| 233 | goto error; |
| 234 | } |
| 235 | error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 236 | handler_threadcxx . . $ handler_thread. = g_thread_try_newcxx . . $ g_thread_try_new(e63133a8f5fd7576).("janus nanomsgevh handler", janus_nanomsgevh_handlercxx . . $ janus_nanomsgevh_handler(9f162e79bfc6c74)., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &error); |
| 237 | if(error != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 238 | g_atomic_int_setcxx . . $ `<external>/742587799302188836/gatomic.h:117:9`!(&initialized, 0); |
| 239 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_FATALcxx . . $ `src/debug.h:41:9`!, "Got error %d (%s) trying to launch the NanomsgEventHandler handler thread...\n", |
| 240 | error->code, error->message ? error->message : "??"); |
| 241 | g_error_freecxx . . $ g_error_free(2ff7d11a2ecc01bd).(error); |
| 242 | goto error; |
| 243 | } |
| 244 | |
| 245 | /* Done */ |
| 246 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_INFOcxx . . $ `src/debug.h:47:9`!, "Setup of Nanomsg event handler completed\n"); |
| 247 | goto done; |
| 248 | |
| 249 | error: |
| 250 | /* If we got here, something went wrong */ |
| 251 | success = FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 252 | if(write_nfdcxx . . $ write_nfd.[0] > -1) |
| 253 | nn_closecxx . . $ nn_close(7864480464b09eea).(write_nfdcxx . . $ write_nfd.[0]); |
| 254 | if(write_nfdcxx . . $ write_nfd.[1] > -1) |
| 255 | nn_closecxx . . $ nn_close(7864480464b09eea).(write_nfdcxx . . $ write_nfd.[1]); |
| 256 | if(nfdcxx . . $ nfd. > -1) { |
| 257 | nn_shutdowncxx . . $ nn_shutdown(9b79fb6aee4c0440).(nfdcxx . . $ nfd., nfd_addrcxx . . $ nfd_addr.); |
| 258 | nn_closecxx . . $ nn_close(7864480464b09eea).(nfdcxx . . $ nfd.); |
| 259 | } |
| 260 | /* Fall through */ |
| 261 | done: |
| 262 | if(config) |
| 263 | janus_config_destroycxx . . $ janus_config_destroy(95a2b4d96b3e84c9).(config); |
| 264 | if(!success) { |
| 265 | return -1; |
| 266 | } |
| 267 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_INFOcxx . . $ `src/debug.h:47:9`!, "%s initialized!\n", JANUS_NANOMSGEVH_NAMEcxx . . $ `src/events/janus_nanomsgevh.c:31:9`!); |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | void janus_nanomsgevh_destroycxx . . $ janus_nanomsgevh_destroy(49f6e7a06ebc5aa8).(void) { |
| 272 | if(!g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&initialized)) |
| 273 | return; |
| 274 | g_atomic_int_setcxx . . $ `<external>/742587799302188836/gatomic.h:117:9`!(&stopping, 1); |
| 275 | |
| 276 | g_async_queue_pushcxx . . $ g_async_queue_push(fd2da36363e73393).(eventscxx . . $ events., &exit_eventcxx . . $ exit_event.); |
| 277 | (void)nn_sendcxx . . $ nn_send(9d1ebb2cd9604347).(write_nfdcxx . . $ write_nfd.[1], "x", 1, 0); |
| 278 | if(pub_threadcxx . . $ pub_thread. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 279 | g_thread_joincxx . . $ g_thread_join(cee1cddadd89739f).(pub_threadcxx . . $ pub_thread.); |
| 280 | pub_threadcxx . . $ pub_thread. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 281 | } |
| 282 | if(handler_threadcxx . . $ handler_thread. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 283 | g_thread_joincxx . . $ g_thread_join(cee1cddadd89739f).(handler_threadcxx . . $ handler_thread.); |
| 284 | handler_threadcxx . . $ handler_thread. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 285 | } |
| 286 | |
| 287 | g_async_queue_unrefcxx . . $ g_async_queue_unref(1fc3c781c06df682).(eventscxx . . $ events.); |
| 288 | eventscxx . . $ events. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 289 | g_async_queue_unrefcxx . . $ g_async_queue_unref(1fc3c781c06df682).(nfd_queuecxx . . $ nfd_queue.); |
| 290 | nfd_queuecxx . . $ nfd_queue. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 291 | |
| 292 | g_atomic_int_setcxx . . $ `<external>/742587799302188836/gatomic.h:117:9`!(&initialized, 0); |
| 293 | g_atomic_int_setcxx . . $ `<external>/742587799302188836/gatomic.h:117:9`!(&stopping, 0); |
| 294 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_INFOcxx . . $ `src/debug.h:47:9`!, "%s destroyed!\n", JANUS_NANOMSGEVH_NAMEcxx . . $ `src/events/janus_nanomsgevh.c:31:9`!); |
| 295 | } |
| 296 | |
| 297 | int janus_nanomsgevh_get_api_compatibilitycxx . . $ janus_nanomsgevh_get_api_compatibility(b126dc7c1de90089).(void) { |
| 298 | /* Important! This is what your plugin MUST always return: don't lie here or bad things will happen */ |
| 299 | return JANUS_EVENTHANDLER_API_VERSIONcxx . . $ `src/events/eventhandler.h:104:9`!; |
| 300 | } |
| 301 | |
| 302 | int janus_nanomsgevh_get_versioncxx . . $ janus_nanomsgevh_get_version(b126dc7c1de90089).(void) { |
| 303 | return JANUS_NANOMSGEVH_VERSIONcxx . . $ `src/events/janus_nanomsgevh.c:28:9`!; |
| 304 | } |
| 305 | |
| 306 | const char *janus_nanomsgevh_get_version_stringcxx . . $ janus_nanomsgevh_get_version_string(33a1f659e94feb42).(void) { |
| 307 | return JANUS_NANOMSGEVH_VERSION_STRINGcxx . . $ `src/events/janus_nanomsgevh.c:29:9`!; |
| 308 | } |
| 309 | |
| 310 | const char *janus_nanomsgevh_get_descriptioncxx . . $ janus_nanomsgevh_get_description(33a1f659e94feb42).(void) { |
| 311 | return JANUS_NANOMSGEVH_DESCRIPTIONcxx . . $ `src/events/janus_nanomsgevh.c:30:9`!; |
| 312 | } |
| 313 | |
| 314 | const char *janus_nanomsgevh_get_namecxx . . $ janus_nanomsgevh_get_name(33a1f659e94feb42).(void) { |
| 315 | return JANUS_NANOMSGEVH_NAMEcxx . . $ `src/events/janus_nanomsgevh.c:31:9`!; |
| 316 | } |
| 317 | |
| 318 | const char *janus_nanomsgevh_get_authorcxx . . $ janus_nanomsgevh_get_author(33a1f659e94feb42).(void) { |
| 319 | return JANUS_NANOMSGEVH_AUTHORcxx . . $ `src/events/janus_nanomsgevh.c:32:9`!; |
| 320 | } |
| 321 | |
| 322 | const char *janus_nanomsgevh_get_packagecxx . . $ janus_nanomsgevh_get_package(33a1f659e94feb42).(void) { |
| 323 | return JANUS_NANOMSGEVH_PACKAGEcxx . . $ `src/events/janus_nanomsgevh.c:33:9`!; |
| 324 | } |
| 325 | |
| 326 | void janus_nanomsgevh_incoming_eventcxx . . $ janus_nanomsgevh_incoming_event(f530285a7fd488d8).(json_tcxx . . $ json_t# *event) { |
| 327 | if(g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&stopping) || !g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&initialized)) { |
| 328 | /* Janus is closing or the plugin is */ |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | /* Do NOT handle the event here in this callback! Since Janus notifies you right |
| 333 | * away when something happens, these events are triggered from working threads and |
| 334 | * not some sort of message bus. As such, performing I/O or network operations in |
| 335 | * here could dangerously slow Janus down. Let's just reference and enqueue the event, |
| 336 | * and handle it in our own thread: the event contains a monotonic time indicator of |
| 337 | * when the event actually happened on this machine, so that, if relevant, we can compute |
| 338 | * any delay in the actual event processing ourselves. */ |
| 339 | json_increfcxx . . $ json_incref(d6c74909b48cac1f).(event); |
| 340 | g_async_queue_pushcxx . . $ g_async_queue_push(fd2da36363e73393).(eventscxx . . $ events., event); |
| 341 | } |
| 342 | |
| 343 | json_tcxx . . $ json_t# *janus_nanomsgevh_handle_requestcxx . . $ janus_nanomsgevh_handle_request(d6c74909b48cac1f).(json_tcxx . . $ json_t# *request) { |
| 344 | if(g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&stopping) || !g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&initialized)) { |
| 345 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 346 | } |
| 347 | /* We can use this requests to apply tweaks to the logic */ |
| 348 | int error_code = 0; |
| 349 | char error_cause[512]; |
| 350 | JANUS_VALIDATE_JSON_OBJECTcxx . . $ `src/utils.h:304:9`!(request, request_parameters, |
| 351 | error_code, error_cause, TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!, |
| 352 | JANUS_NANOMSGEVH_ERROR_MISSING_ELEMENTcxx . . $ `src/events/janus_nanomsgevh.c:109:9`!, JANUS_NANOMSGEVH_ERROR_INVALID_ELEMENTcxx . . $ `src/events/janus_nanomsgevh.c:110:9`!); |
| 353 | if(error_code != 0) |
| 354 | goto plugin_response; |
| 355 | /* Get the request */ |
| 356 | const char *request_text = json_string_valuecxx . . $ json_string_value(85321e2e0e6e739).(json_object_getcxx . . $ json_object_get(d1dcf86e9b8660de).(request, "request")); |
| 357 | if(!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(request_text, "tweak")) { |
| 358 | /* We only support a request to tweak the current settings */ |
| 359 | JANUS_VALIDATE_JSON_OBJECTcxx . . $ `src/utils.h:304:9`!(request, tweak_parameters, |
| 360 | error_code, error_cause, TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!, |
| 361 | JANUS_NANOMSGEVH_ERROR_MISSING_ELEMENTcxx . . $ `src/events/janus_nanomsgevh.c:109:9`!, JANUS_NANOMSGEVH_ERROR_INVALID_ELEMENTcxx . . $ `src/events/janus_nanomsgevh.c:110:9`!); |
| 362 | if(error_code != 0) |
| 363 | goto plugin_response; |
| 364 | /* Events */ |
| 365 | if(json_object_getcxx . . $ json_object_get(d1dcf86e9b8660de).(request, "events")) |
| 366 | janus_events_edit_events_maskcxx . . $ janus_events_edit_events_mask(a076e8a1d44d5614).(json_string_valuecxx . . $ json_string_value(85321e2e0e6e739).(json_object_getcxx . . $ json_object_get(d1dcf86e9b8660de).(request, "events")), &janus_nanomsgevhcxx . . $ janus_nanomsgevh..events_maskcxx . . $ janus_eventhandler#events_mask.); |
| 367 | /* Grouping */ |
| 368 | if(json_object_getcxx . . $ json_object_get(d1dcf86e9b8660de).(request, "grouping")) |
| 369 | group_eventscxx . . $ group_events. = json_is_truecxx . . $ `<external>/8172222224910760005/jansson.h:87:9`!(json_object_get(request, "grouping")); |
| 370 | } else { |
| 371 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "Unknown request '%s'\n", request_text); |
| 372 | error_code = JANUS_NANOMSGEVH_ERROR_INVALID_REQUESTcxx . . $ `src/events/janus_nanomsgevh.c:108:9`!; |
| 373 | g_snprintfcxx . . $ g_snprintf(ea502d73e74c754c).(error_cause, 512, "Unknown request '%s'", request_text); |
| 374 | } |
| 375 | |
| 376 | plugin_response: |
| 377 | { |
| 378 | json_tcxx . . $ json_t# *response = json_objectcxx . . $ json_object(ddf554718f1c8728).(); |
| 379 | if(error_code == 0) { |
| 380 | /* Return a success */ |
| 381 | json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(response, "result", json_integercxx . . $ json_integer(90ae68dba811b408).(200)); |
| 382 | } else { |
| 383 | /* Prepare JSON error event */ |
| 384 | json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(response, "error_code", json_integercxx . . $ json_integer(90ae68dba811b408).(error_code)); |
| 385 | json_object_set_newcxx . . $ json_object_set_new(6a89ae69e2653183).(response, "error", json_stringcxx . . $ json_string(2f6de68c9404c25a).(error_cause)); |
| 386 | } |
| 387 | return response; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | /* Thread to handle incoming events */ |
| 392 | static void *janus_nanomsgevh_handlercxx . . $ janus_nanomsgevh_handler(9f162e79bfc6c74).(void *data) { |
| 393 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "Joining NanomsgEventHandler handler thread\n"); |
| 394 | json_tcxx . . $ json_t# *event = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, *output = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 395 | char *event_text = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 396 | int count = 0, max = group_eventscxx . . $ group_events. ? 100 : 1; |
| 397 | |
| 398 | while(g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&initialized) && !g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&stopping)) { |
| 399 | |
| 400 | event = g_async_queue_popcxx . . $ g_async_queue_pop(624ec77f9da27fb1).(eventscxx . . $ events.); |
| 401 | if(event == &exit_eventcxx . . $ exit_event.) |
| 402 | break; |
| 403 | count = 0; |
| 404 | output = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 405 | |
| 406 | while(TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!) { |
| 407 | /* Handle event: just for fun, let's see how long it took for us to take care of this */ |
| 408 | json_tcxx . . $ json_t# *created = json_object_getcxx . . $ json_object_get(d1dcf86e9b8660de).(event, "timestamp"); |
| 409 | if(created && json_is_integercxx . . $ `<external>/8172222224910760005/jansson.h:84:9`!(created)) { |
| 410 | gint64cxx . . $ gint64# then = json_integer_valuecxx . . $ json_integer_value(3fcc9c381023a61c).(created); |
| 411 | gint64cxx . . $ gint64# now = janus_get_monotonic_timecxx . . $ janus_get_monotonic_time(da6335ded91d79c2).(); |
| 412 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_DBGcxx . . $ `src/debug.h:53:9`!, "Handled event after %"SCNu64cxx . . $ `<external>/15933738808807975373/inttypes.h:245:10`!" us\n", now-then); |
| 413 | } |
| 414 | if(!group_eventscxx . . $ group_events.) { |
| 415 | /* We're done here, we just need a single event */ |
| 416 | output = event; |
| 417 | break; |
| 418 | } |
| 419 | /* If we got here, we're grouping */ |
| 420 | if(output == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 421 | output = json_arraycxx . . $ json_array(ddf554718f1c8728).(); |
| 422 | json_array_append_newcxx . . $ json_array_append_new(120152faeb96c420).(output, event); |
| 423 | /* Never group more than a maximum number of events, though, or we might stay here forever */ |
| 424 | count++; |
| 425 | if(count == max) |
| 426 | break; |
| 427 | event = g_async_queue_try_popcxx . . $ g_async_queue_try_pop(624ec77f9da27fb1).(eventscxx . . $ events.); |
| 428 | if(event == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || event == &exit_eventcxx . . $ exit_event.) |
| 429 | break; |
| 430 | } |
| 431 | |
| 432 | if(!g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&stopping)) { |
| 433 | /* Since this a simple plugin, it does the same for all events: so just convert to string... */ |
| 434 | event_text = json_dumpscxx . . $ json_dumps(2d3f8bb6f822a904).(output, json_formatcxx . . $ json_format.); |
| 435 | if(event_text == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 436 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_WARNcxx . . $ `src/debug.h:45:9`!, "Failed to stringify event, event lost...\n"); |
| 437 | /* Nothing we can do... get rid of the event */ |
| 438 | json_decrefcxx . . $ json_decref(f530285a7fd488d8).(output); |
| 439 | output = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 440 | continue; |
| 441 | } |
| 442 | g_async_queue_pushcxx . . $ g_async_queue_push(fd2da36363e73393).(nfd_queuecxx . . $ nfd_queue., event_text); |
| 443 | (void)nn_sendcxx . . $ nn_send(9d1ebb2cd9604347).(write_nfdcxx . . $ write_nfd.[1], "x", 1, 0); |
| 444 | } |
| 445 | |
| 446 | /* Done, let's unref the event */ |
| 447 | json_decrefcxx . . $ json_decref(f530285a7fd488d8).(output); |
| 448 | output = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 449 | } |
| 450 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "Leaving NanomsgEventHandler handler thread\n"); |
| 451 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 452 | } |
| 453 | |
| 454 | /* Thread */ |
| 455 | void *janus_nanomsgevh_threadcxx . . $ janus_nanomsgevh_thread(9f162e79bfc6c74).(void *data) { |
| 456 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "Joining NanomsgEventHandler loop thread\n"); |
| 457 | |
| 458 | int fds = 0; |
| 459 | struct nn_pollfdcxx . . $ nn_pollfd# poll_nfds[2]; |
| 460 | char buffer[1]; |
| 461 | |
| 462 | while(g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&initialized) && !g_atomic_int_getcxx . . $ `<external>/742587799302188836/gatomic.h:109:9`!(&stopping)) { |
| 463 | /* Prepare poll list of file descriptors */ |
| 464 | fds = 0; |
| 465 | /* Writeable monitor */ |
| 466 | poll_nfds[fds].fdcxx . . $ nn_pollfd#fd. = write_nfdcxx . . $ write_nfd.[0]; |
| 467 | poll_nfds[fds].eventscxx . . $ nn_pollfd#events. = NN_POLLINcxx . . $ `<external>/13568548034321366761/nn.h:364:9`!; |
| 468 | fds++; |
| 469 | /* Publisher socket */ |
| 470 | if(nfdcxx . . $ nfd. > -1 && g_async_queue_lengthcxx . . $ g_async_queue_length(5a676b5b2a16ae3b).(nfd_queuecxx . . $ nfd_queue.) > 0) { |
| 471 | poll_nfds[fds].fdcxx . . $ nn_pollfd#fd. = nfdcxx . . $ nfd.; |
| 472 | poll_nfds[fds].eventscxx . . $ nn_pollfd#events. |= NN_POLLOUTcxx . . $ `<external>/13568548034321366761/nn.h:365:9`!; |
| 473 | fds++; |
| 474 | } |
| 475 | /* Start polling */ |
| 476 | int res = nn_pollcxx . . $ nn_poll(7ca859798f8df785).(poll_nfds, fds, -1); |
| 477 | if(res == 0) |
| 478 | continue; |
| 479 | if(res < 0) { |
| 480 | if(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!) { |
| 481 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_HUGEcxx . . $ `src/debug.h:51:9`!, "Got an EINTR (%s) polling the Nanomsg descriptors, ignoring...\n", nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 482 | continue; |
| 483 | } |
| 484 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_ERRcxx . . $ `src/debug.h:43:9`!, "poll() failed: %d (%s)\n", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, nn_strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 485 | break; |
| 486 | } |
| 487 | int i = 0; |
| 488 | for(i=0; i<fds; i++) { |
| 489 | /* FIXME Is there a Nanomsg equivalent of POLLERR? */ |
| 490 | if(poll_nfds[i].reventscxx . . $ nn_pollfd#revents. & NN_POLLOUTcxx . . $ `<external>/13568548034321366761/nn.h:365:9`!) { |
| 491 | /* Find the client from its file descriptor */ |
| 492 | if(poll_nfds[i].fdcxx . . $ nn_pollfd#fd. == nfdcxx . . $ nfd.) { |
| 493 | char *payload = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 494 | while((payload = g_async_queue_try_popcxx . . $ g_async_queue_try_pop(624ec77f9da27fb1).(nfd_queuecxx . . $ nfd_queue.)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 495 | int res = nn_sendcxx . . $ nn_send(9d1ebb2cd9604347).(poll_nfds[i].fdcxx . . $ nn_pollfd#fd., payload, strlencxx . . $ strlen(751346f8406fd082).(payload), 0); |
| 496 | /* FIXME Should we check if sent everything? */ |
| 497 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_HUGEcxx . . $ `src/debug.h:51:9`!, "Written %d/%zu bytes on %d\n", res, strlen(payload), poll_nfds[i].fd); |
| 498 | g_freecxx . . $ g_free(5d22bdacc48458e8).(payload); |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | if(poll_nfds[i].reventscxx . . $ nn_pollfd#revents. & NN_POLLINcxx . . $ `<external>/13568548034321366761/nn.h:364:9`!) { |
| 503 | if(poll_nfds[i].fdcxx . . $ nn_pollfd#fd. == write_nfdcxx . . $ write_nfd.[0]) { |
| 504 | /* Read and ignore: we use this to unlock the poll if there's data to write */ |
| 505 | (void)nn_recvcxx . . $ nn_recv(6076e73854a1e617).(poll_nfds[i].fdcxx . . $ nn_pollfd#fd., buffer, sizeof(buffer), 0); |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | nn_closecxx . . $ nn_close(7864480464b09eea).(write_nfdcxx . . $ write_nfd.[0]); |
| 512 | nn_closecxx . . $ nn_close(7864480464b09eea).(write_nfdcxx . . $ write_nfd.[1]); |
| 513 | if(nfdcxx . . $ nfd. > -1) { |
| 514 | nn_shutdowncxx . . $ nn_shutdown(9b79fb6aee4c0440).(nfdcxx . . $ nfd., nfd_addrcxx . . $ nfd_addr.); |
| 515 | nn_closecxx . . $ nn_close(7864480464b09eea).(nfdcxx . . $ nfd.); |
| 516 | } |
| 517 | |
| 518 | /* Done */ |
| 519 | JANUS_LOGcxx . . $ `src/debug.h:91:9`!(LOG_VERBcxx . . $ `src/debug.h:49:9`!, "Leaving NanomsgEventHandler loop thread\n"); |
| 520 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 521 | } |