1d4afb5ceSopenharmony_ci/* 2d4afb5ceSopenharmony_ci * libwebsockets - small server side websockets and web server implementation 3d4afb5ceSopenharmony_ci * 4d4afb5ceSopenharmony_ci * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com> 5d4afb5ceSopenharmony_ci * 6d4afb5ceSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 7d4afb5ceSopenharmony_ci * of this software and associated documentation files (the "Software"), to 8d4afb5ceSopenharmony_ci * deal in the Software without restriction, including without limitation the 9d4afb5ceSopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10d4afb5ceSopenharmony_ci * sell copies of the Software, and to permit persons to whom the Software is 11d4afb5ceSopenharmony_ci * furnished to do so, subject to the following conditions: 12d4afb5ceSopenharmony_ci * 13d4afb5ceSopenharmony_ci * The above copyright notice and this permission notice shall be included in 14d4afb5ceSopenharmony_ci * all copies or substantial portions of the Software. 15d4afb5ceSopenharmony_ci * 16d4afb5ceSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17d4afb5ceSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18d4afb5ceSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19d4afb5ceSopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20d4afb5ceSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21d4afb5ceSopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22d4afb5ceSopenharmony_ci * IN THE SOFTWARE. 23d4afb5ceSopenharmony_ci */ 24d4afb5ceSopenharmony_ci 25d4afb5ceSopenharmony_ci#include <uv.h> 26d4afb5ceSopenharmony_ci 27d4afb5ceSopenharmony_ci/* 28d4afb5ceSopenharmony_ci * libuv's async destroy cb means that asking to close something doesn't mean 29d4afb5ceSopenharmony_ci * you can destroy it or parent things until after the close completes. 30d4afb5ceSopenharmony_ci * 31d4afb5ceSopenharmony_ci * So we must reference-count creation and close completions with libuv. 32d4afb5ceSopenharmony_ci * 33d4afb5ceSopenharmony_ci * All "static" (per-pt or per-context) uv handles must 34d4afb5ceSopenharmony_ci * 35d4afb5ceSopenharmony_ci * - have their .data set to point to the context 36d4afb5ceSopenharmony_ci * 37d4afb5ceSopenharmony_ci * - contribute to context->uv_count_static_asset_handles 38d4afb5ceSopenharmony_ci * counting 39d4afb5ceSopenharmony_ci */ 40d4afb5ceSopenharmony_ci#define LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(_x, _pt) \ 41d4afb5ceSopenharmony_ci { uv_handle_t *_uht = (uv_handle_t *)(_x); _uht->data = _pt; \ 42d4afb5ceSopenharmony_ci _pt->count_event_loop_static_asset_handles++; } 43d4afb5ceSopenharmony_ci#define LWS_UV_REFCOUNT_STATIC_HANDLE_TO_PT(_x) \ 44d4afb5ceSopenharmony_ci ((struct lws_context_per_thread *)((uv_handle_t *)((_x)->data))) 45d4afb5ceSopenharmony_ci#define LWS_UV_REFCOUNT_STATIC_HANDLE_DESTROYED(_x) \ 46d4afb5ceSopenharmony_ci (--(LWS_UV_REFCOUNT_STATIC_HANDLE_TO_PT(_x)-> \ 47d4afb5ceSopenharmony_ci count_event_loop_static_asset_handles)) 48d4afb5ceSopenharmony_ci 49d4afb5ceSopenharmony_cistruct lws_signal_watcher_libuv { 50d4afb5ceSopenharmony_ci uv_signal_t watcher; 51d4afb5ceSopenharmony_ci struct lws_context *context; 52d4afb5ceSopenharmony_ci}; 53d4afb5ceSopenharmony_ci 54d4afb5ceSopenharmony_cistruct lws_pt_eventlibs_libuv { 55d4afb5ceSopenharmony_ci uv_loop_t *io_loop; 56d4afb5ceSopenharmony_ci struct lws_context_per_thread *pt; 57d4afb5ceSopenharmony_ci uv_signal_t signals[8]; 58d4afb5ceSopenharmony_ci uv_timer_t sultimer; 59d4afb5ceSopenharmony_ci uv_idle_t idle; 60d4afb5ceSopenharmony_ci 61d4afb5ceSopenharmony_ci uv_thread_t uv_thread; 62d4afb5ceSopenharmony_ci 63d4afb5ceSopenharmony_ci struct lws_signal_watcher_libuv w_sigint; 64d4afb5ceSopenharmony_ci int extant_handles; 65d4afb5ceSopenharmony_ci 66d4afb5ceSopenharmony_ci char thread_valid; 67d4afb5ceSopenharmony_ci}; 68d4afb5ceSopenharmony_ci 69d4afb5ceSopenharmony_cistruct lws_context_eventlibs_libuv { 70d4afb5ceSopenharmony_ci uv_loop_t loop; 71d4afb5ceSopenharmony_ci}; 72d4afb5ceSopenharmony_ci 73d4afb5ceSopenharmony_cistruct lws_io_watcher_libuv { 74d4afb5ceSopenharmony_ci uv_poll_t *pwatcher; 75d4afb5ceSopenharmony_ci struct lws_context *context; 76d4afb5ceSopenharmony_ci uint8_t actual_events; 77d4afb5ceSopenharmony_ci}; 78d4afb5ceSopenharmony_ci 79d4afb5ceSopenharmony_cistruct lws_wsi_eventlibs_libuv { 80d4afb5ceSopenharmony_ci struct lws_io_watcher_libuv w_read; 81d4afb5ceSopenharmony_ci}; 82d4afb5ceSopenharmony_ci 83d4afb5ceSopenharmony_ciuv_loop_t * 84d4afb5ceSopenharmony_cilws_uv_getloop(struct lws_context *context, int tsi); 85d4afb5ceSopenharmony_ci 86d4afb5ceSopenharmony_ciint 87d4afb5ceSopenharmony_cilws_uv_plugins_init(struct lws_context *context, const char * const *d); 88d4afb5ceSopenharmony_ci 89d4afb5ceSopenharmony_ciint 90d4afb5ceSopenharmony_cilws_uv_plugins_destroy(struct lws_context *context); 91