{"schema":"libjg2-1",
"vpath":"/git/",
"avatar":"/git/avatar/",
"alang":"",
"gen_ut":1731493741,
"reponame":"libwebsockets",
"desc":"libwebsockets lightweight C networking library",
"owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets",
"f":3,
"items": [
{"schema":"libjg2-1",
"cid":"a2a5129c510d29b2f31dc2ed9d6aca2b",
"oid":{ "oid": "6328231f2aa628632344d96a58e25c3b194af506", "alias": [ "refs/heads/main"]},"blobname": "lib/plat/unix/unix-service.c", "blob": "/*\n * libwebsockets - small server side websockets and web server implementation\n *\n * Copyright (C) 2010 - 2019 Andy Green \u003candy@warmcat.com\u003e\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \u0022Software\u0022), to\n * deal in the Software without restriction, including without limitation the\n * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n * sell copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \u0022AS IS\u0022, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n * IN THE SOFTWARE.\n */\n\n#if !defined(_GNU_SOURCE)\n#define _GNU_SOURCE\n#endif\n#include \u0022private-lib-core.h\u0022\n\nint\nlws_poll_listen_fd(struct lws_pollfd *fd)\n{\n\treturn poll(fd, 1, 0);\n}\n\nint\n_lws_plat_service_forced_tsi(struct lws_context *context, int tsi)\n{\n\tstruct lws_context_per_thread *pt \u003d \u0026context-\u003ept[tsi];\n\tint m, n, r;\n\n\tr \u003d lws_service_flag_pending(context, tsi);\n\n\t/* any socket with events to service? */\n\tfor (n \u003d 0; n \u003c (int)pt-\u003efds_count; n++) {\n\t\tlws_sockfd_type fd \u003d pt-\u003efds[n].fd;\n\n\t\tif (!pt-\u003efds[n].revents)\n\t\t\tcontinue;\n\n\t\tm \u003d lws_service_fd_tsi(context, \u0026pt-\u003efds[n], tsi);\n\t\tif (m \u003c 0) {\n\t\t\tlwsl_err(\u0022%s: lws_service_fd_tsi returned %d\u005cn\u0022,\n\t\t\t\t __func__, m);\n\t\t\treturn -1;\n\t\t}\n\n\t\t/* if something closed, retry this slot since may have been\n\t\t * swapped with end fd */\n\t\tif (m \u0026\u0026 pt-\u003efds[n].fd !\u003d fd)\n\t\t\tn--;\n\t}\n\n\tlws_service_do_ripe_rxflow(pt);\n\n\treturn r;\n}\n\n#define LWS_POLL_WAIT_LIMIT 2000000000\n\nint\n_lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi)\n{\n\tvolatile struct lws_foreign_thread_pollfd *ftp, *next;\n\tvolatile struct lws_context_per_thread *vpt;\n\tstruct lws_context_per_thread *pt;\n\tlws_usec_t timeout_us, us;\n#if defined(LWS_WITH_SYS_METRICS)\n\tlws_usec_t a, b;\n#endif\n\tint n;\n#if (defined(LWS_ROLE_WS) \u0026\u0026 !defined(LWS_WITHOUT_EXTENSIONS)) || defined(LWS_WITH_TLS)\n\tint m;\n#endif\n\n\t/* stay dead once we are dead */\n\n\tif (!context)\n\t\treturn 1;\n\n#if defined(LWS_WITH_SYS_METRICS)\n\tb \u003d\n#endif\n\t\t\tus \u003d lws_now_usecs();\n\n\tpt \u003d \u0026context-\u003ept[tsi];\n\tvpt \u003d (volatile struct lws_context_per_thread *)pt;\n\n\tif (timeout_ms \u003c 0)\n\t\ttimeout_ms \u003d 0;\n\telse\n\t\t/* force a default timeout of 23 days */\n\t\ttimeout_ms \u003d LWS_POLL_WAIT_LIMIT;\n\ttimeout_us \u003d ((lws_usec_t)timeout_ms) * LWS_US_PER_MS;\n\n\tif (context-\u003eevent_loop_ops-\u003erun_pt)\n\t\tcontext-\u003eevent_loop_ops-\u003erun_pt(context, tsi);\n\n\tif (!pt-\u003eservice_tid_detected \u0026\u0026 context-\u003evhost_list) {\n\t\tlws_fakewsi_def_plwsa(pt);\n\n\t\tlws_fakewsi_prep_plwsa_ctx(context);\n\n\t\tpt-\u003eservice_tid \u003d context-\u003evhost_list-\u003eprotocols[0].callback(\n\t\t\t\t\t(struct lws *)plwsa,\n\t\t\t\t\tLWS_CALLBACK_GET_THREAD_ID,\n\t\t\t\t\tNULL, NULL, 0);\n\t\tpt-\u003eservice_tid_detected \u003d 1;\n\t}\n\n\tlws_pt_lock(pt, __func__);\n\t/*\n\t * service ripe scheduled events, and limit wait to next expected one\n\t */\n\tus \u003d __lws_sul_service_ripe(pt-\u003ept_sul_owner, LWS_COUNT_PT_SUL_OWNERS, us);\n\tif (us \u0026\u0026 us \u003c timeout_us)\n\t\t/*\n\t\t * If something wants zero wait, that's OK, but if the next sul\n\t\t * coming ripe is an interval less than our wait resolution,\n\t\t * bump it to be the wait resolution.\n\t\t */\n\t\ttimeout_us \u003d us \u003c context-\u003eus_wait_resolution ?\n\t\t\t\t\tcontext-\u003eus_wait_resolution : us;\n\n\tlws_pt_unlock(pt);\n\n\t/*\n\t * is there anybody with pending stuff that needs service forcing?\n\t */\n\tif (!lws_service_adjust_timeout(context, 1, tsi))\n\t\ttimeout_us \u003d 0;\n\n\t/* ensure we don't wrap at 2^31 with poll()'s signed int ms */\n\n\ttimeout_us /\u003d LWS_US_PER_MS; /* ms now */\n\n#if defined(LWS_WITH_SYS_METRICS)\n\ta \u003d lws_now_usecs() - b;\n#endif\n\tvpt-\u003einside_poll \u003d 1;\n\tlws_memory_barrier();\n\tn \u003d poll(pt-\u003efds, pt-\u003efds_count, (int)timeout_us /* ms now */ );\n\tvpt-\u003einside_poll \u003d 0;\n\tlws_memory_barrier();\n\n#if defined(LWS_WITH_SYS_METRICS)\n\tb \u003d lws_now_usecs();\n#endif\n\t/* Collision will be rare and brief. Spin until it completes */\n\twhile (vpt-\u003eforeign_spinlock)\n\t\t;\n\n\t/*\n\t * At this point we are not inside a foreign thread pollfd\n\t * change, and we have marked ourselves as outside the poll()\n\t * wait. So we are the only guys that can modify the\n\t * lws_foreign_thread_pollfd list on the pt. Drain the list\n\t * and apply the changes to the affected pollfds in the correct\n\t * order.\n\t */\n\n\tlws_pt_lock(pt, __func__);\n\n\tftp \u003d vpt-\u003eforeign_pfd_list;\n\t//lwsl_notice(\u0022cleared list %p\u005cn\u0022, ftp);\n\twhile (ftp) {\n\t\tstruct lws *wsi;\n\t\tstruct lws_pollfd *pfd;\n\n\t\tnext \u003d ftp-\u003enext;\n\t\tpfd \u003d \u0026vpt-\u003efds[ftp-\u003efd_index];\n\t\tif (lws_socket_is_valid(pfd-\u003efd)) {\n\t\t\twsi \u003d wsi_from_fd(context, pfd-\u003efd);\n\t\t\tif (wsi)\n\t\t\t\t__lws_change_pollfd(wsi, ftp-\u003e_and,\n\t\t\t\t\t\t ftp-\u003e_or);\n\t\t}\n\t\tlws_free((void *)ftp);\n\t\tftp \u003d next;\n\t}\n\tvpt-\u003eforeign_pfd_list \u003d NULL;\n\tlws_memory_barrier();\n\n\tlws_pt_unlock(pt);\n\n#if (defined(LWS_ROLE_WS) \u0026\u0026 !defined(LWS_WITHOUT_EXTENSIONS)) || defined(LWS_WITH_TLS)\n\tm \u003d 0;\n#endif\n#if defined(LWS_ROLE_WS) \u0026\u0026 !defined(LWS_WITHOUT_EXTENSIONS)\n\tm |\u003d !!pt-\u003ews.rx_draining_ext_list;\n#endif\n\n#if defined(LWS_WITH_TLS)\n\tif (pt-\u003econtext-\u003etls_ops \u0026\u0026\n\t pt-\u003econtext-\u003etls_ops-\u003efake_POLLIN_for_buffered)\n\t\tm |\u003d pt-\u003econtext-\u003etls_ops-\u003efake_POLLIN_for_buffered(pt);\n#endif\n\n\tif (\n#if (defined(LWS_ROLE_WS) \u0026\u0026 !defined(LWS_WITHOUT_EXTENSIONS)) || defined(LWS_WITH_TLS)\n\t\t!m \u0026\u0026\n#endif\n\t\t!n) /* nothing to do */\n\t\tlws_service_do_ripe_rxflow(pt);\n\telse\n\t\tif (_lws_plat_service_forced_tsi(context, tsi) \u003c 0)\n\t\t\treturn -1;\n\n#if defined(LWS_WITH_SYS_METRICS)\n\tlws_metric_event(context-\u003emt_service, METRES_GO,\n\t\t\t (u_mt_t) (a + (lws_now_usecs() - b)));\n#endif\n\n\tif (pt-\u003edestroy_self) {\n\t\tlws_context_destroy(pt-\u003econtext);\n\t\treturn -1;\n\t}\n\n\treturn 0;\n}\n\nint\nlws_plat_service(struct lws_context *context, int timeout_ms)\n{\n\treturn _lws_plat_service_tsi(context, timeout_ms, 0);\n}\n","s":{"c":1731493741,"u": 328}}
],"g": 2339,"chitpc": 0,"ehitpc": 0,"indexed":0
,
"ab": 1, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}