2 * libwebsockets - small server side websockets and web server implementation
4 * Copyright (C) 2010 - 2018 Andy Green <andy@warmcat.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation:
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
23 #define _WINSOCK_DEPRECATED_NO_WARNINGS
25 #include "core/private.h"
28 wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd)
30 int h = LWS_FD_HASH(fd);
33 for (n = 0; n < context->fd_hashtable[h].length; n++)
34 if (context->fd_hashtable[h].wsi[n]->desc.sockfd == fd)
35 return context->fd_hashtable[h].wsi[n];
41 insert_wsi(struct lws_context *context, struct lws *wsi)
43 int h = LWS_FD_HASH(wsi->desc.sockfd);
45 if (context->fd_hashtable[h].length == (getdtablesize() - 1)) {
46 lwsl_err("hash table overflow\n");
50 context->fd_hashtable[h].wsi[context->fd_hashtable[h].length++] = wsi;
56 delete_from_fd(struct lws_context *context, lws_sockfd_type fd)
58 int h = LWS_FD_HASH(fd);
61 for (n = 0; n < context->fd_hashtable[h].length; n++)
62 if (context->fd_hashtable[h].wsi[n]->desc.sockfd == fd) {
63 while (n < context->fd_hashtable[h].length) {
64 context->fd_hashtable[h].wsi[n] =
65 context->fd_hashtable[h].wsi[n + 1];
68 context->fd_hashtable[h].length--;
73 lwsl_err("Failed to find fd %d requested for "
74 "delete in hashtable\n", fd);