diff options
Diffstat (limited to 'lib/core-net/client/connect4.c')
-rw-r--r-- | lib/core-net/client/connect4.c | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/lib/core-net/client/connect4.c b/lib/core-net/client/connect4.c index 89611202..8e13dc03 100644 --- a/lib/core-net/client/connect4.c +++ b/lib/core-net/client/connect4.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com> + * Copyright (C) 2010 - 2021 Andy Green <andy@warmcat.com> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -95,7 +95,8 @@ lws_client_connect_4_established(struct lws *wsi, struct lws *wsi_piggyback, goto failed; wsi->c_port = (uint16_t)wsi->a.vhost->http.http_proxy_port; - n = (int)send(wsi->desc.sockfd, (char *)pt->serv_buf, (unsigned int)plen, + n = (int)send(wsi->desc.sockfd, (char *)pt->serv_buf, + (unsigned int)plen, MSG_NOSIGNAL); if (n < 0) { lwsl_debug("ERROR writing to proxy socket\n"); @@ -161,14 +162,18 @@ send_hs: __func__, wsi->lc.gutag, lwsi_state(wsi_piggyback)); } else { lwsl_info("%s: %s: %s %s client created own conn " - "(raw %d) vh %sm st 0x%x\n", - __func__, wsi->lc.gutag, wsi->role_ops->name, - wsi->a.protocol->name, rawish, wsi->a.vhost->name, - lwsi_state(wsi)); + "(raw %d) vh %sm st 0x%x\n", __func__, wsi->lc.gutag, + wsi->role_ops->name, wsi->a.protocol->name, rawish, + wsi->a.vhost->name, lwsi_state(wsi)); /* we are making our own connection */ - if (!rawish) { + if (!rawish +#if defined(LWS_WITH_TLS) + // && (!(wsi->tls.use_ssl & LCCSCF_USE_SSL) || wsi->tls.ssl) +#endif + ) { + if (lwsi_state(wsi) != LRS_H1C_ISSUE_HANDSHAKE2) lwsi_set_state(wsi, LRS_H1C_ISSUE_HANDSHAKE); } else { @@ -183,20 +188,24 @@ send_hs: (wsi->tls.use_ssl & LCCSCF_USE_SSL)) { int result; + //lwsi_set_state(wsi, LRS_WAITING_SSL); + /* * We can retry this... just cook the SSL BIO * the first time */ result = lws_client_create_tls(wsi, &cce, 1); - lwsl_debug("%s: create_tls said %d\n", - __func__, result); switch (result) { case CCTLS_RETURN_DONE: break; case CCTLS_RETURN_RETRY: + lwsl_debug("%s: create_tls RETRY\n", + __func__); return wsi; default: + lwsl_debug("%s: create_tls FAIL\n", + __func__); goto failed; } @@ -207,9 +216,10 @@ send_hs: * LRS_H2_WAITING_TO_SEND_HEADERS already. */ - lwsl_notice("%s: %s: " - "tls established st 0x%x\n", - __func__, wsi->lc.gutag, lwsi_state(wsi)); + lwsl_notice("%s: %s: tls established st 0x%x, " + "client_h2_alpn %d\n", __func__, + wsi->lc.gutag, lwsi_state(wsi), + wsi->client_h2_alpn); if (lwsi_state(wsi) != LRS_H2_WAITING_TO_SEND_HEADERS) @@ -217,7 +227,13 @@ send_hs: LRS_H1C_ISSUE_HANDSHAKE2); lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND, - (int)wsi->a.context->timeout_secs); + (int)wsi->a.context->timeout_secs); +#if 0 + /* ensure pollin enabled */ + if (lws_change_pollfd(wsi, 0, LWS_POLLIN)) + lwsl_notice("%s: unable to set POLLIN\n", + __func__); +#endif goto provoke_service; } @@ -230,7 +246,8 @@ send_hs: if (m) { n = user_callback_handle_rxflow( wsi->a.protocol->callback, wsi, - (enum lws_callback_reasons)m, wsi->user_space, NULL, 0); + (enum lws_callback_reasons)m, + wsi->user_space, NULL, 0); if (n < 0) { lwsl_info("RAW_PROXY_CLI_ADOPT err\n"); goto failed; @@ -240,7 +257,7 @@ send_hs: /* service.c pollout processing wants this */ wsi->hdr_parsing_completed = 1; #if defined(LWS_ROLE_MQTT) - if (!strcmp(meth, "MQTT")) { + if (meth && !strcmp(meth, "MQTT")) { #if defined(LWS_WITH_TLS) if (wsi->tls.use_ssl & LCCSCF_USE_SSL) { lwsi_set_state(wsi, LRS_WAITING_SSL); @@ -320,7 +337,7 @@ provoke_service: failed: lws_inform_client_conn_fail(wsi, (void *)cce, strlen(cce)); - lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "client_connect2"); + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "client_connect4"); return NULL; } |