mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-30 00:00:16 +01:00
client: connect report actual socket error to user callback rather than EINPROGRESS
https://github.com/warmcat/libwebsockets/pull/2452
This commit is contained in:
parent
6d88669b69
commit
76a5a9e2f2
1 changed files with 17 additions and 5 deletions
|
@ -71,7 +71,7 @@ typedef enum {
|
|||
} lcccr_t;
|
||||
|
||||
static lcccr_t
|
||||
lws_client_connect_check(struct lws *wsi)
|
||||
lws_client_connect_check(struct lws *wsi, int *real_errno)
|
||||
{
|
||||
#if !defined(LWS_WITH_NO_LOGS)
|
||||
char t16[16];
|
||||
|
@ -103,6 +103,8 @@ lws_client_connect_check(struct lws *wsi)
|
|||
lwsl_wsi_notice(wsi, "getsockopt fd %d says %s", wsi->desc.sockfd,
|
||||
lws_errno_describe(e, t16, sizeof(t16)));
|
||||
|
||||
*real_errno = e;
|
||||
|
||||
return LCCCR_FAILED;
|
||||
}
|
||||
|
||||
|
@ -133,7 +135,7 @@ lws_client_connect_check(struct lws *wsi)
|
|||
#endif
|
||||
|
||||
lwsl_wsi_notice(wsi, "connect check FAILED: %s",
|
||||
lws_errno_describe(en, t16, sizeof(t16)));
|
||||
lws_errno_describe(*real_errno || en, t16, sizeof(t16)));
|
||||
|
||||
return LCCCR_FAILED;
|
||||
}
|
||||
|
@ -238,7 +240,15 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,
|
|||
/* no dns results and no ongoing timeout for one */
|
||||
goto connect_to;
|
||||
|
||||
switch (lws_client_connect_check(wsi)) {
|
||||
/*
|
||||
* If the connection failed, the OS-level errno may be
|
||||
* something like EINPROGRESS rather than the actual problem
|
||||
* that prevented a connection. This value will represent the
|
||||
* “real” problem that we should report to the caller.
|
||||
*/
|
||||
int real_errno = 0;
|
||||
|
||||
switch (lws_client_connect_check(wsi, &real_errno)) {
|
||||
case LCCCR_CONNECTED:
|
||||
/*
|
||||
* Oh, it has happened...
|
||||
|
@ -247,9 +257,11 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,
|
|||
case LCCCR_CONTINUE:
|
||||
return NULL;
|
||||
default:
|
||||
en = LWS_ERRNO;
|
||||
if (!real_errno)
|
||||
real_errno = LWS_ERRNO;
|
||||
lws_snprintf(dcce, sizeof(dcce), "conn fail: %s",
|
||||
lws_errno_describe(en, t16, sizeof(t16)));
|
||||
lws_errno_describe(real_errno, t16, sizeof(t16)));
|
||||
|
||||
cce = dcce;
|
||||
lwsl_wsi_debug(wsi, "%s", dcce);
|
||||
lws_metrics_caliper_report(wsi->cal_conn, METRES_NOGO);
|
||||
|
|
Loading…
Add table
Reference in a new issue