diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 2eaaceb9..94608202 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -1567,6 +1567,34 @@ libwebsocket_callback_on_writable_all_protocol( return 0; } +/** + * libwebsocket_callback_all_protocol() - Callback all connections using + * the given protocol with the given reason + * + * @protocol: Protocol whose connections will get callbacks + * @reason: Callback reason index + */ + +LWS_VISIBLE int +libwebsocket_callback_all_protocol( + const struct libwebsocket_protocols *protocol, int reason) +{ + struct libwebsocket_context *context = protocol->owning_server; + int n; + struct libwebsocket *wsi; + + for (n = 0; n < context->fds_count; n++) { + wsi = context->lws_lookup[context->fds[n].fd]; + if (!wsi) + continue; + if (wsi->protocol == protocol) + protocol->callback(context, wsi, + reason, wsi->user_space, NULL, 0); + } + + return 0; +} + /** * libwebsocket_set_timeout() - marks the wsi as subject to a timeout * diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 676d50e7..527d2500 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -1042,6 +1042,10 @@ LWS_VISIBLE LWS_EXTERN int libwebsocket_callback_on_writable_all_protocol( const struct libwebsocket_protocols *protocol); +LWS_VISIBLE LWS_EXTERN int +libwebsocket_callback_all_protocol( + const struct libwebsocket_protocols *protocol, int reason); + LWS_VISIBLE LWS_EXTERN int libwebsocket_get_socket_fd(struct libwebsocket *wsi);