struct lws * wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd) { int h = LWS_FD_HASH(fd); int n = 0; for (n = 0; n < context->fd_hashtable[h].length; n++) if (context->fd_hashtable[h].wsi[n]->sock == fd) return context->fd_hashtable[h].wsi[n]; return NULL; }
struct libwebsocket * wsi_from_fd(struct libwebsocket_context *context, int fd) { int h = LWS_FD_HASH(fd); int n = 0; for (n = 0; n < context->fd_hashtable[h].length; n++) if (context->fd_hashtable[h].wsi[n]->sock == fd) return context->fd_hashtable[h].wsi[n]; return NULL; }
int insert_wsi(struct lws_context *context, struct lws *wsi) { int h = LWS_FD_HASH(wsi->sock); if (context->fd_hashtable[h].length == (getdtablesize() - 1)) { lwsl_err("hash table overflow\n"); return 1; } context->fd_hashtable[h].wsi[context->fd_hashtable[h].length++] = wsi; return 0; }
int delete_from_fd(struct lws_context *context, lws_sockfd_type fd) { int h = LWS_FD_HASH(fd); int n = 0; for (n = 0; n < context->fd_hashtable[h].length; n++) if (context->fd_hashtable[h].wsi[n]->sock == fd) { while (n < context->fd_hashtable[h].length) { context->fd_hashtable[h].wsi[n] = context->fd_hashtable[h].wsi[n + 1]; n++; } context->fd_hashtable[h].length--; return 0; } lwsl_err("Failed to find fd %d requested for " "delete in hashtable\n", fd); return 1; }