Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1713601408, "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":"27641ca6d4e72ef61f550e426199c22f", "commit": {"type":"commit", "time": 1525562545, "time_ofs": 480, "oid_tree": { "oid": "9da5da47299d1d0f2195291ec4b556e5d8558bc0", "alias": []}, "oid":{ "oid": "c4dc102a0b99b75d87cc93816bc6b8a90d5b8b03", "alias": []}, "msg": "windows: cleanup wrong and duplicated socket validity helpers", "sig_commit": { "git_time": { "time": 1525562545, "offset": 480 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }, "sig_author": { "git_time": { "time": 1525562361, "offset": 480 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }}, "body": "windows: cleanup wrong and duplicated socket validity helpers\n\nhttps://github.com/warmcat/libwebsockets/issues/1259" , "diff": "diff --git a/lib/core/libwebsockets.c b/lib/core/libwebsockets.c\nindex 4360e95..8eedbf8 100644\n--- a/lib/core/libwebsockets.c\n+++ b/lib/core/libwebsockets.c\n@@ -751,7 +751,7 @@ just_kill_connection:\n \t\t\t\t __func__, wsi, (int)(long)wsi-\u003edesc.sockfd,\n \t\t\t\t lwsi_state(wsi));\n \t\t\tif (!wsi-\u003esocket_is_permanently_unusable \u0026\u0026\n-\t\t\t lws_sockfd_valid(wsi-\u003edesc.sockfd)) {\n+\t\t\t lws_socket_is_valid(wsi-\u003edesc.sockfd)) {\n \t\t\t\twsi-\u003esocket_is_permanently_unusable \u003d 1;\n \t\t\t\tn \u003d shutdown(wsi-\u003edesc.sockfd, SHUT_WR);\n \t\t\t}\n@@ -767,7 +767,7 @@ just_kill_connection:\n #if !defined(_WIN32_WCE) \u0026\u0026 !defined(LWS_WITH_ESP32)\n \t\t/* libuv: no event available to guarantee completion */\n \t\tif (!wsi-\u003esocket_is_permanently_unusable \u0026\u0026\n-\t\t lws_sockfd_valid(wsi-\u003edesc.sockfd) \u0026\u0026\n+\t\t lws_socket_is_valid(wsi-\u003edesc.sockfd) \u0026\u0026\n \t\t lwsi_state(wsi) !\u003d LRS_SHUTDOWN \u0026\u0026\n \t\t context-\u003eevent_loop_ops-\u003eperiodic_events_available) {\n \t\t\t__lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN);\n@@ -3326,7 +3326,8 @@ lws_stats_log_dump(struct lws_context *context)\n \tcontext-\u003eupdated \u003d 1;\n \n \twhile (v) {\n-\t\tif (v-\u003elserv_wsi) {\n+\t\tif (v-\u003elserv_wsi \u0026\u0026\n+\t\t v-\u003elserv_wsi-\u003eposition_in_fds_table !\u003d LWS_NO_FDS_POS) {\n \n \t\t\tstruct lws_context_per_thread *pt \u003d\n \t\t\t\t\t\u0026context-\u003ept[(int)v-\u003elserv_wsi-\u003etsi];\ndiff --git a/lib/core/pollfd.c b/lib/core/pollfd.c\nindex fbc6132..2a632ce 100644\n--- a/lib/core/pollfd.c\n+++ b/lib/core/pollfd.c\n@@ -33,7 +33,13 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa)\n \tstruct lws_pollfd *pfd;\n \tint sampled_tid, tid;\n \n-\tif (!wsi || wsi-\u003eposition_in_fds_table \u003c 0)\n+\tif (!wsi)\n+\t\treturn 0;\n+\n+\tassert(wsi-\u003eposition_in_fds_table \u003d\u003d LWS_NO_FDS_POS ||\n+\t wsi-\u003eposition_in_fds_table \u003e\u003d 0);\n+\n+\tif (wsi-\u003eposition_in_fds_table \u003d\u003d LWS_NO_FDS_POS)\n \t\treturn 0;\n \n \tif (((volatile struct lws *)wsi)-\u003ehandling_pollout \u0026\u0026\n@@ -60,8 +66,7 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa)\n \tcontext \u003d wsi-\u003econtext;\n \tpt \u003d \u0026context-\u003ept[(int)wsi-\u003etsi];\n \n-\tassert(wsi-\u003eposition_in_fds_table \u003e\u003d 0 \u0026\u0026\n-\t wsi-\u003eposition_in_fds_table \u003c (int)pt-\u003efds_count);\n+\tassert(wsi-\u003eposition_in_fds_table \u003c (int)pt-\u003efds_count);\n \n #if !defined(LWS_WITH_LIBUV) \u0026\u0026 \u005c\n !defined(LWS_WITH_LIBEV) \u0026\u0026 \u005c\n@@ -316,6 +321,10 @@ __remove_wsi_socket_from_fds(struct lws *wsi)\n \t/* the guy who is to be deleted's slot index in pt-\u003efds */\n \tm \u003d wsi-\u003eposition_in_fds_table;\n \t\n+\t/* these are the only valid possibilities for position_in_fds_table */\n+\tassert(m \u003d\u003d LWS_NO_FDS_POS || (m \u003e\u003d 0 \u0026\u0026\n+\t\t\t\t (unsigned int)m \u003c pt-\u003efds_count));\n+\n \tif (context-\u003eevent_loop_ops-\u003eio)\n \t\tcontext-\u003eevent_loop_ops-\u003eio(wsi,\n \t\t\t\t LWS_EV_STOP | LWS_EV_READ | LWS_EV_WRITE |\n@@ -325,7 +334,7 @@ __remove_wsi_socket_from_fds(struct lws *wsi)\n \t\t __func__, wsi, wsi-\u003edesc.sockfd, wsi-\u003eposition_in_fds_table,\n \t\t pt-\u003efds_count, pt-\u003efds[pt-\u003efds_count].fd);\n \n-\tif (m !\u003d LWS_SOCK_INVALID) {\n+\tif (m !\u003d LWS_NO_FDS_POS) {\n \n \t\t/* have the last guy take up the now vacant slot */\n \t\tpt-\u003efds[m] \u003d pt-\u003efds[pt-\u003efds_count - 1];\n@@ -335,16 +344,17 @@ __remove_wsi_socket_from_fds(struct lws *wsi)\n \t\t/* end guy's \u0022position in fds table\u0022 is now the deletion guy's old one */\n \t\tend_wsi \u003d wsi_from_fd(context, v);\n \t\tif (!end_wsi) {\n-\t\t\tlwsl_err(\u0022no wsi found for fd %d at pos %d, pt-\u003efds_count\u003d%d\u005cn\u0022,\n-\t\t\t\t(int)pt-\u003efds[m].fd, m, pt-\u003efds_count);\n+\t\t\tlwsl_err(\u0022no wsi for fd %d at pos %d, pt-\u003efds_count\u003d%d\u005cn\u0022,\n+\t\t\t\t (int)pt-\u003efds[m].fd, m, pt-\u003efds_count);\n \t\t\tassert(0);\n \t\t} else\n \t\t\tend_wsi-\u003eposition_in_fds_table \u003d m;\n \n \t\t/* deletion guy's lws_lookup entry needs nuking */\n \t\tdelete_from_fd(context, wsi-\u003edesc.sockfd);\n+\n \t\t/* removed wsi has no position any more */\n-\t\twsi-\u003eposition_in_fds_table \u003d -1;\n+\t\twsi-\u003eposition_in_fds_table \u003d LWS_NO_FDS_POS;\n \t}\n \n \t/* remove also from external POLL support via protocol 0 */\n@@ -376,7 +386,7 @@ __lws_change_pollfd(struct lws *wsi, int _and, int _or)\n \tint ret \u003d 0;\n \n \tif (!wsi || (!wsi-\u003eprotocol \u0026\u0026 !wsi-\u003eevent_pipe) ||\n-\t wsi-\u003eposition_in_fds_table \u003c 0)\n+\t wsi-\u003eposition_in_fds_table \u003d\u003d LWS_NO_FDS_POS)\n \t\treturn 0;\n \n \tcontext \u003d lws_get_context(wsi);\n@@ -458,7 +468,7 @@ lws_callback_on_writable(struct lws *wsi)\n \t\twsi \u003d lws_get_network_wsi(wsi);\n \t}\n \n-\tif (wsi-\u003eposition_in_fds_table \u003c 0) {\n+\tif (wsi-\u003eposition_in_fds_table \u003d\u003d LWS_NO_FDS_POS) {\n \t\tlwsl_debug(\u0022%s: failed to find socket %d\u005cn\u0022, __func__,\n \t\t\t wsi-\u003edesc.sockfd);\n \t\treturn -1;\ndiff --git a/lib/core/private.h b/lib/core/private.h\nindex b31b693..d6b494a 100644\n--- a/lib/core/private.h\n+++ b/lib/core/private.h\n@@ -92,8 +92,8 @@\n \n #define compatible_close(fd) closesocket(fd)\n #define lws_set_blocking_send(wsi) wsi-\u003esock_send_blocking \u003d 1\n- #define lws_socket_is_valid(x) (!!x)\n #define LWS_SOCK_INVALID (INVALID_SOCKET)\n+\n #include \u003cwinsock2.h\u003e\n #include \u003cws2tcpip.h\u003e\n #include \u003cwindows.h\u003e\n@@ -189,7 +189,6 @@\n \n #define lws_set_blocking_send(wsi)\n \n- #define lws_socket_is_valid(x) (x \u003e\u003d 0)\n #define LWS_SOCK_INVALID (-1)\n #endif /* not windows */\n \n@@ -203,6 +202,9 @@\n #define strerror(x) \u0022\u0022\n #endif\n \n+\n+#define lws_socket_is_valid(x) (x !\u003d LWS_SOCK_INVALID)\n+\n #include \u0022libwebsockets.h\u0022\n \n #include \u0022tls/private.h\u0022\n@@ -1069,11 +1071,6 @@ struct lws {\n \tstruct lws_lws_tls tls;\n #endif\n \n-#ifdef LWS_LATENCY\n-\tunsigned long action_start;\n-\tunsigned long latency_start;\n-#endif\n-\n \tlws_sock_file_fd_type desc; /* .filefd / .sockfd */\n #if defined(LWS_WITH_STATS)\n \tuint64_t active_writable_req_us;\n@@ -1085,7 +1082,13 @@ struct lws {\n \tlws_usec_t pending_timer; /* hrtimer fires */\n \ttime_t pending_timeout_set; /* second-resolution timeout start */\n \n+#ifdef LWS_LATENCY\n+\tunsigned long action_start;\n+\tunsigned long latency_start;\n+#endif\n+\n \t/* ints */\n+#define LWS_NO_FDS_POS (-1)\n \tint position_in_fds_table;\n \tunsigned int trunc_alloc_len; /* size of malloc */\n \tunsigned int trunc_offset; /* where we are in terms of spilling */\ndiff --git a/lib/event-libs/libuv/libuv.c b/lib/event-libs/libuv/libuv.c\nindex b5c8b85..57947d4 100644\n--- a/lib/event-libs/libuv/libuv.c\n+++ b/lib/event-libs/libuv/libuv.c\n@@ -562,7 +562,7 @@ elops_destroy_context2_uv(struct lws_context *context)\n static int\n elops_wsi_logical_close_uv(struct lws *wsi)\n {\n-\tif (wsi-\u003eparent_carries_io || !lws_sockfd_valid(wsi-\u003edesc.sockfd))\n+\tif (wsi-\u003eparent_carries_io || !lws_socket_is_valid(wsi-\u003edesc.sockfd))\n \t\treturn 0;\n \n \tif (wsi-\u003elistener || wsi-\u003eevent_pipe) {\ndiff --git a/lib/libwebsockets.h b/lib/libwebsockets.h\nindex c4f8bcb..cf4cb51 100644\n--- a/lib/libwebsockets.h\n+++ b/lib/libwebsockets.h\n@@ -481,7 +481,7 @@ typedef int64_t lws_usec_t;\n #if defined(_WIN32)\n typedef SOCKET lws_sockfd_type;\n typedef HANDLE lws_filefd_type;\n-#define lws_sockfd_valid(sfd) (!!sfd)\n+\n struct lws_pollfd {\n \tlws_sockfd_type fd; /**\u003c file descriptor */\n \tSHORT events; /**\u003c which events to respond to */\n@@ -497,7 +497,7 @@ struct lws_pollfd {\n \n typedef int lws_sockfd_type;\n typedef int lws_filefd_type;\n-#define lws_sockfd_valid(sfd) (sfd \u003e\u003d 0)\n+\n struct pollfd {\n \tlws_sockfd_type fd; /**\u003c fd related to */\n \tshort events; /**\u003c which POLL... events to respond to */\n@@ -701,7 +701,6 @@ extern void lws_esp32_leds_timer_cb(TimerHandle_t th);\n #else\n typedef int lws_sockfd_type;\n typedef int lws_filefd_type;\n-#define lws_sockfd_valid(sfd) (sfd \u003e\u003d 0)\n #endif\n \n #define lws_pollfd pollfd\ndiff --git a/lib/plat/lws-plat-unix.c b/lib/plat/lws-plat-unix.c\nindex 5b59f20..bacc6af 100644\n--- a/lib/plat/lws-plat-unix.c\n+++ b/lib/plat/lws-plat-unix.c\n@@ -239,7 +239,7 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi)\n \n \t\tnext \u003d ftp-\u003enext;\n \t\tpfd \u003d \u0026vpt-\u003efds[ftp-\u003efd_index];\n-\t\tif (lws_sockfd_valid(pfd-\u003efd)) {\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, ftp-\u003e_or);\ndiff --git a/lib/roles/cgi/cgi-server.c b/lib/roles/cgi/cgi-server.c\nindex e5a466a..964a3df 100644\n--- a/lib/roles/cgi/cgi-server.c\n+++ b/lib/roles/cgi/cgi-server.c\n@@ -91,7 +91,7 @@ lws_create_basic_wsi(struct lws_context *context, int tsi)\n \tlws_role_transition(new_wsi, 0, LRS_ESTABLISHED, \u0026role_ops_cgi);\n \n \tnew_wsi-\u003ehdr_parsing_completed \u003d 0;\n-\tnew_wsi-\u003eposition_in_fds_table \u003d -1;\n+\tnew_wsi-\u003eposition_in_fds_table \u003d LWS_NO_FDS_POS;\n \n \t/*\n \t * these can only be set once the protocol is known\ndiff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c\nindex 337ccea..4830fc9 100644\n--- a/lib/roles/http/client/client-handshake.c\n+++ b/lib/roles/http/client/client-handshake.c\n@@ -577,7 +577,7 @@ oom4:\n \t\twsi-\u003ealready_did_cce \u003d 1;\n \t}\n \t/* take care that we might be inserted in fds already */\n-\tif (wsi-\u003eposition_in_fds_table !\u003d -1)\n+\tif (wsi-\u003eposition_in_fds_table !\u003d LWS_NO_FDS_POS)\n \t\tgoto failed1;\n \tlws_remove_from_timeout_list(wsi);\n #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)\n@@ -923,7 +923,7 @@ lws_client_connect_via_info(struct lws_client_connect_info *i)\n \n \twsi-\u003euser_space \u003d NULL;\n \twsi-\u003epending_timeout \u003d NO_PENDING_TIMEOUT;\n-\twsi-\u003eposition_in_fds_table \u003d -1;\n+\twsi-\u003eposition_in_fds_table \u003d LWS_NO_FDS_POS;\n \twsi-\u003ec_port \u003d i-\u003eport;\n \twsi-\u003evhost \u003d i-\u003evhost;\n \tif (!wsi-\u003evhost)\ndiff --git a/lib/roles/http/server/parsers.c b/lib/roles/http/server/parsers.c\nindex 054a839..cb022e3 100644\n--- a/lib/roles/http/server/parsers.c\n+++ b/lib/roles/http/server/parsers.c\n@@ -110,7 +110,8 @@ __lws_header_table_reset(struct lws *wsi, int autoservice)\n \n \ttime(\u0026ah-\u003eassigned);\n \n-\tif (lws_buflist_next_segment_len(\u0026wsi-\u003ebuflist, NULL) \u0026\u0026\n+\tif (wsi-\u003eposition_in_fds_table !\u003d LWS_NO_FDS_POS \u0026\u0026\n+\t lws_buflist_next_segment_len(\u0026wsi-\u003ebuflist, NULL) \u0026\u0026\n \t autoservice) {\n \t\tlwsl_debug(\u0022%s: service on readbuf ah\u005cn\u0022, __func__);\n \n@@ -366,7 +367,7 @@ int __lws_header_table_detach(struct lws *wsi, int autoservice)\n #endif\n \n \t/* clients acquire the ah and then insert themselves in fds table... */\n-\tif (wsi-\u003eposition_in_fds_table !\u003d -1) {\n+\tif (wsi-\u003eposition_in_fds_table !\u003d LWS_NO_FDS_POS) {\n \t\tlwsl_info(\u0022%s: Enabling %p POLLIN\u005cn\u0022, __func__, wsi);\n \n \t\t/* he has been stuck waiting for an ah, but now his wait is\ndiff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c\nindex f55a137..350af3c 100644\n--- a/lib/roles/http/server/server.c\n+++ b/lib/roles/http/server/server.c\n@@ -1695,7 +1695,7 @@ lws_create_new_server_wsi(struct lws_vhost *vhost, int fixed_tsi)\n \tnew_wsi-\u003eprotocol \u003d vhost-\u003eprotocols;\n \tnew_wsi-\u003euser_space \u003d NULL;\n \tnew_wsi-\u003edesc.sockfd \u003d LWS_SOCK_INVALID;\n-\tnew_wsi-\u003eposition_in_fds_table \u003d -1;\n+\tnew_wsi-\u003eposition_in_fds_table \u003d LWS_NO_FDS_POS;\n \n \tvhost-\u003econtext-\u003ecount_wsi_allocated++;\n \n@@ -2075,6 +2075,9 @@ adopt_socket_readbuf(struct lws *wsi, const char *readbuf, size_t len)\n \tif (!readbuf || len \u003d\u003d 0)\n \t\treturn wsi;\n \n+\tif (wsi-\u003eposition_in_fds_table \u003d\u003d LWS_NO_FDS_POS)\n+\t\treturn wsi;\n+\n \tpt \u003d \u0026wsi-\u003econtext-\u003ept[(int)wsi-\u003etsi];\n \n \tn \u003d lws_buflist_append_segment(\u0026wsi-\u003ebuflist, (const uint8_t *)readbuf, len);\ndiff --git a/lib/roles/listen/ops-listen.c b/lib/roles/listen/ops-listen.c\nindex 0e46323..dbeb975 100644\n--- a/lib/roles/listen/ops-listen.c\n+++ b/lib/roles/listen/ops-listen.c\n@@ -124,7 +124,7 @@ rops_handle_POLLIN_listen(struct lws_context_per_thread *pt, struct lws *wsi,\n \n \t\tfd.sockfd \u003d accept_fd;\n \t\tcwsi \u003d lws_adopt_descriptor_vhost(wsi-\u003evhost, opts, fd,\n-\t\t\t\t\t\tNULL, NULL);\n+\t\t\t\t\t\t NULL, NULL);\n \t\tif (!cwsi)\n \t\t\t/* already closed cleanly as necessary */\n \t\t\treturn LWS_HPI_RET_WSI_ALREADY_DIED;\n@@ -139,6 +139,7 @@ rops_handle_POLLIN_listen(struct lws_context_per_thread *pt, struct lws *wsi,\n \t\t\t __func__, cwsi, cwsi-\u003ewsistate, cwsi-\u003erole_ops-\u003ename);\n \n \t} while (pt-\u003efds_count \u003c context-\u003efd_limit_per_thread - 1 \u0026\u0026\n+\t\t wsi-\u003eposition_in_fds_table !\u003d LWS_NO_FDS_POS \u0026\u0026\n \t\t lws_poll_listen_fd(\u0026pt-\u003efds[wsi-\u003eposition_in_fds_table]) \u003e 0);\n \n \treturn LWS_HPI_RET_HANDLED;\ndiff --git a/lib/roles/ws/ops-ws.c b/lib/roles/ws/ops-ws.c\nindex fd036c3..310a3be 100644\n--- a/lib/roles/ws/ops-ws.c\n+++ b/lib/roles/ws/ops-ws.c\n@@ -1448,7 +1448,7 @@ rops_service_flag_pending_ws(struct lws_context *context, int tsi)\n \t * not flowcontrolled, fake their POLLIN status\n \t */\n \twsi \u003d pt-\u003ews.rx_draining_ext_list;\n-\twhile (wsi) {\n+\twhile (wsi \u0026\u0026 wsi-\u003eposition_in_fds_table !\u003d LWS_NO_FDS_POS) {\n \t\tpt-\u003efds[wsi-\u003eposition_in_fds_table].revents |\u003d\n \t\t\tpt-\u003efds[wsi-\u003eposition_in_fds_table].events \u0026 LWS_POLLIN;\n \t\tif (pt-\u003efds[wsi-\u003eposition_in_fds_table].revents \u0026 LWS_POLLIN)\ndiff --git a/lib/tls/tls.c b/lib/tls/tls.c\nindex c865c89..640a283 100644\n--- a/lib/tls/tls.c\n+++ b/lib/tls/tls.c\n@@ -34,7 +34,7 @@ lws_tls_fake_POLLIN_for_buffered(struct lws_context_per_thread *pt)\n \tint ret \u003d 0;\n \n \twsi \u003d pt-\u003etls.pending_read_list;\n-\twhile (wsi) {\n+\twhile (wsi \u0026\u0026 wsi-\u003eposition_in_fds_table !\u003d LWS_NO_FDS_POS) {\n \t\twsi_next \u003d wsi-\u003etls.pending_read_list_next;\n \t\tpt-\u003efds[wsi-\u003eposition_in_fds_table].revents |\u003d\n \t\t\tpt-\u003efds[wsi-\u003eposition_in_fds_table].events \u0026 LWS_POLLIN;\n","s":{"c":1713601408,"u": 14769}} ],"g": 16106,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}