Skip to content

Commit

Permalink
client: add CONNECTING protocol cb
Browse files Browse the repository at this point in the history
  • Loading branch information
lws-team committed Apr 5, 2021
1 parent d291c02 commit b582dd4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions include/libwebsockets/lws-callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,15 @@ enum lws_callback_reasons {
* destroyed. in is the child wsi.
*/

LWS_CALLBACK_CONNECTING = 105,
/**< Called before a socketfd is about to connect(). In is the
* socketfd, cast to a (void *), if on a platform where the socketfd
* is an int, recover portably using (lws_sockfd_type)(intptr_t)in.
*
* It's also called in SOCKS5 or http_proxy cases where the socketfd is
* going to try to connect to its proxy.
*/

/* ---------------------------------------------------------------------
* ----- Callbacks related to TLS certificate management -----
*/
Expand Down
11 changes: 10 additions & 1 deletion lib/core-net/client/connect3.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,22 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,

wsi->socket_is_permanently_unusable = 0;

if (lws_fi(&wsi->fic, "conn_cb_rej") ||
user_callback_handle_rxflow(wsi->a.protocol->callback, wsi,
LWS_CALLBACK_CONNECTING, wsi->user_space,
(void *)(intptr_t)wsi->desc.sockfd, 0)) {
lwsl_info("%s: CONNECTION CB closed\n", __func__);
goto failed1;
}

#if defined(LWS_WITH_SYS_FAULT_INJECTION)
cfail = lws_fi(&wsi->fic, "connfail");
if (cfail)
m = -1;
else
#endif
m = connect(wsi->desc.sockfd, (const struct sockaddr *)psa, (unsigned int)n);
m = connect(wsi->desc.sockfd, (const struct sockaddr *)psa,
(unsigned int)n);

#if defined(LWS_WITH_CONMON)
wsi->conmon_datum = lws_now_usecs();
Expand Down

0 comments on commit b582dd4

Please sign in to comment.