From 3f17a8e25217427db37e1d269279132b2ece8d23 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Wed, 15 Jun 2016 10:46:58 +0800 Subject: [PATCH] lws_callback_vhost_protocols This gives protocols a way to talk to each other via per-vhost callbacks, one per protocol (including the sender). Signed-off-by: Andy Green --- lib/libwebsockets.c | 25 +++++++++++++++++++++++++ lib/libwebsockets.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index e229ab3..05b2664 100755 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -907,6 +907,31 @@ lws_callback_all_protocol_vhost(struct lws_vhost *vh, return 0; } +/** + * lws_callback_vhost_protocols() - Callback all protocols enabled on a vhost + * with the given reason + * + * @wsi: wsi whose vhost will get callbacks + * @reason: Callback reason index + * @in: in argument to callback + * @len: len argument to callback + * + * This is useful when informing all fellow enabled protocols on a vhost about + * a vhost-wide event, eg, creation or deletion of an account + */ + +LWS_VISIBLE LWS_EXTERN int +lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len) +{ + int n; + + for (n = 0; n < wsi->vhost->count_protocols; n++) + if (wsi->vhost->protocols[n].callback(wsi, reason, NULL, in, len)) + return 1; + + return 0; +} + #if LWS_POSIX /** diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index aff7493..3b17d45 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -2072,6 +2072,9 @@ lws_callback_all_protocol_vhost(struct lws_vhost *vh, const struct lws_protocols *protocol, int reason); LWS_VISIBLE LWS_EXTERN int +lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len); + +LWS_VISIBLE LWS_EXTERN int lws_get_socket_fd(struct lws *wsi); LWS_VISIBLE LWS_EXTERN int -- 2.7.4