Skip to content

Commit 9022885

Browse files
authored
Merge pull request #176 from c-jimenez/fix/websocket_connect_timeout
[websockets] Fix websocket connect timeout configuration + flush messages on disconnect
2 parents a086cec + 910d02c commit 9022885

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/websockets/libwebsockets/LibWebsocketClient.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ bool LibWebsocketClient::connect(const std::string& url,
9898
info.port = CONTEXT_PORT_NO_LISTEN;
9999
info.protocols = protocols;
100100
info.timeout_secs = static_cast<unsigned int>(std::chrono::duration_cast<std::chrono::seconds>(connect_timeout).count());
101-
info.log_cx = &m_logs_context;
102-
m_credentials = credentials;
101+
info.connect_timeout_secs =
102+
static_cast<unsigned int>(std::chrono::duration_cast<std::chrono::seconds>(connect_timeout).count());
103+
info.log_cx = &m_logs_context;
104+
m_credentials = credentials;
103105
if (m_url.protocol() == "wss")
104106
{
105107
if (!m_credentials.tls12_cipher_list.empty())
@@ -505,6 +507,12 @@ int LibWebsocketClient::eventCallback(struct lws* wsi, enum lws_callback_reasons
505507
{
506508
retry = true;
507509
}
510+
511+
SendMsg* msg;
512+
while (client->m_send_msgs.pop(msg, 0))
513+
{
514+
delete msg;
515+
}
508516
break;
509517

510518
default:

src/websockets/libwebsockets/LibWebsocketClientPool.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void LibWebsocketClientPool::process()
144144

145145
// Dummy vhost to handle context related events
146146
struct lws_protocols protocols[] = {{"LibWebsocketClientPool", &LibWebsocketClientPool::eventCallback, 0, 0, 0, this, 0},
147-
LWS_PROTOCOL_LIST_TERM};
147+
LWS_PROTOCOL_LIST_TERM};
148148
struct lws_context_creation_info vhost_info;
149149
memset(&vhost_info, 0, sizeof(vhost_info));
150150
vhost_info.protocols = protocols;
@@ -443,11 +443,12 @@ void LibWebsocketClientPool::Client::connectCallback(struct lws_sorted_usec_list
443443
// Fill vhost information
444444
struct lws_context_creation_info vhost_info;
445445
memset(&vhost_info, 0, sizeof(vhost_info));
446-
vhost_info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
447-
vhost_info.port = CONTEXT_PORT_NO_LISTEN;
448-
vhost_info.timeout_secs = client->m_connect_timeout;
449-
vhost_info.protocols = protocols;
450-
vhost_info.log_cx = &pool->m_logs_context;
446+
vhost_info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
447+
vhost_info.port = CONTEXT_PORT_NO_LISTEN;
448+
vhost_info.timeout_secs = client->m_connect_timeout;
449+
vhost_info.connect_timeout_secs = client->m_connect_timeout;
450+
vhost_info.protocols = protocols;
451+
vhost_info.log_cx = &pool->m_logs_context;
451452
if (client->m_url.protocol() == "wss")
452453
{
453454
if (!client->m_credentials.tls12_cipher_list.empty())
@@ -686,6 +687,12 @@ int LibWebsocketClientPool::Client::eventCallback(
686687
{
687688
retry = true;
688689
}
690+
691+
SendMsg* msg;
692+
while (client->m_send_msgs.pop(msg, 0))
693+
{
694+
delete msg;
695+
}
689696
break;
690697

691698
default:

0 commit comments

Comments
 (0)