From a91ed1fa4c01e416152c5b7cc4bda6b5274804ac Mon Sep 17 00:00:00 2001 From: Andy Green Date: Wed, 14 Mar 2018 17:36:02 +0800 Subject: [PATCH] client: CONNECTION_ERROR: target at local protocol if possible Until now LWS_CALLBACK_CLIENT_CONNECTION_ERROR handling could only take place on protocols[0]. This patch changes LWS_CALLBACK_CLIENT_CONNECTION_ERROR to be sent to the protocol the client connection was bound to... if nothing better that is still protocols[0], but if you created the client connection using info.local_protocol_name, it will now be sent to the bound protocol handler instead. --- lib/client/client-handshake.c | 4 ++-- lib/libwebsockets.c | 2 +- lib/service.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/client/client-handshake.c b/lib/client/client-handshake.c index a6b98fd6e..984d710e6 100644 --- a/lib/client/client-handshake.c +++ b/lib/client/client-handshake.c @@ -413,7 +413,7 @@ oom4: if (wsi->mode == LWSCM_HTTP_CLIENT || wsi->mode == LWSCM_HTTP_CLIENT_ACCEPTED || wsi->mode == LWSCM_WSCL_WAITING_CONNECT) { - wsi->vhost->protocols[0].callback(wsi, + wsi->protocol->callback(wsi, LWS_CALLBACK_CLIENT_CONNECTION_ERROR, wsi->user_space, (void *)cce, strlen(cce)); wsi->already_did_cce = 1; @@ -429,7 +429,7 @@ oom4: return NULL; failed: - wsi->vhost->protocols[0].callback(wsi, + wsi->protocol->callback(wsi, LWS_CALLBACK_CLIENT_CONNECTION_ERROR, wsi->user_space, (void *)cce, strlen(cce)); wsi->already_did_cce = 1; diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index a1d082453..f1a028c9e 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -696,7 +696,7 @@ just_kill_connection: if ((wsi->mode == LWSCM_WSCL_WAITING_SERVER_REPLY || wsi->mode == LWSCM_WSCL_WAITING_CONNECT) && !wsi->already_did_cce) { - wsi->vhost->protocols[0].callback(wsi, + wsi->protocol->callback(wsi, LWS_CALLBACK_CLIENT_CONNECTION_ERROR, wsi->user_space, NULL, 0); } diff --git a/lib/service.c b/lib/service.c index 00e19d875..ca8fb82d9 100644 --- a/lib/service.c +++ b/lib/service.c @@ -741,7 +741,7 @@ __lws_service_timeout_check(struct lws *wsi, time_t sec) */ wsi->socket_is_permanently_unusable = 1; if (wsi->mode == LWSCM_WSCL_WAITING_SSL) - wsi->vhost->protocols[0].callback(wsi, + wsi->protocol->callback(wsi, LWS_CALLBACK_CLIENT_CONNECTION_ERROR, wsi->user_space, (void *)"Timed out waiting SSL", 21); @@ -1317,7 +1317,7 @@ lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd, wsi->context = context; wsi->vhost = v; wsi->protocol = q->protocol; - lwsl_notice("timed cb: vh %s, protocol %s, reason %d\n", v->name, q->protocol->name, q->reason); + lwsl_debug("timed cb: vh %s, protocol %s, reason %d\n", v->name, q->protocol->name, q->reason); q->protocol->callback(wsi, q->reason, NULL, NULL, 0); nx = q->next; lws_timed_callback_remove(v, q);