mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00

Until now the uv watcher has been composed in the wsi. This works fine except in the case of a client wsi that meets a redirect when the event loop is libuv with its requirement for handle close via the event loop. We want to reuse the wsi, since the originator of it has a copy of the wsi pointer, and we want to conceal the redirect. Since the redirect is commonly to a different IP, we want to keep the wsi alive while closing its socket cleanly. That's not too difficult, unless you are using uv. With UV the comoposed watcher is a disaster, since after the close is requested the wsi will start to reconnect. We tried to deal with that by copying the uv handle and freeing it when the handle close finalizes. But it turns out the handle is in a linked-list scheme in uv. This patch hopefully finally solves it by giving the uv handle its own allocation from the start. When we want to close the socket and reuse the wsi, we simply take responsibility for freeing the handle and set the wsi watcher pointer to NULL.
74 lines
2.5 KiB
C
74 lines
2.5 KiB
C
/*
|
|
* libwebsockets - small server side websockets and web server implementation
|
|
*
|
|
* Copyright (C) 2010 - 2018 Andy Green <andy@warmcat.com>
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation:
|
|
* version 2.1 of the License.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
* MA 02110-1301 USA
|
|
*
|
|
* This is included from core/private.h
|
|
*/
|
|
|
|
struct lws_event_loop_ops {
|
|
const char *name;
|
|
/* event loop-specific context init during context creation */
|
|
int (*init_context)(struct lws_context *context,
|
|
const struct lws_context_creation_info *info);
|
|
/* called during lws_destroy_context */
|
|
int (*destroy_context1)(struct lws_context *context);
|
|
/* called during lws_destroy_context2 */
|
|
int (*destroy_context2)(struct lws_context *context);
|
|
/* init vhost listening wsi */
|
|
int (*init_vhost_listen_wsi)(struct lws *wsi);
|
|
/* init the event loop for a pt */
|
|
int (*init_pt)(struct lws_context *context, void *_loop, int tsi);
|
|
/* called at end of first phase of close_free_wsi() */
|
|
int (*wsi_logical_close)(struct lws *wsi);
|
|
/* return nonzero if client connect not allowed */
|
|
int (*check_client_connect_ok)(struct lws *wsi);
|
|
/* close handle manually */
|
|
void (*close_handle_manually)(struct lws *wsi);
|
|
/* event loop accept processing */
|
|
int (*accept)(struct lws *wsi);
|
|
/* control wsi active events */
|
|
void (*io)(struct lws *wsi, int flags);
|
|
/* run the event loop for a pt */
|
|
void (*run_pt)(struct lws_context *context, int tsi);
|
|
/* called before pt is destroyed */
|
|
void (*destroy_pt)(struct lws_context *context, int tsi);
|
|
/* called just before wsi is freed */
|
|
void (*destroy_wsi)(struct lws *wsi);
|
|
|
|
unsigned int periodic_events_available:1;
|
|
};
|
|
|
|
/* bring in event libs private declarations */
|
|
|
|
#if defined(LWS_WITH_POLL)
|
|
#include "event-libs/poll/private.h"
|
|
#endif
|
|
|
|
#if defined(LWS_WITH_LIBUV)
|
|
#include "event-libs/libuv/private.h"
|
|
#endif
|
|
|
|
#if defined(LWS_WITH_LIBEVENT)
|
|
#include "event-libs/libevent/private.h"
|
|
#endif
|
|
|
|
#if defined(LWS_WITH_LIBEV)
|
|
#include "event-libs/libev/private.h"
|
|
#endif
|
|
|