aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoni Poikelin <joni.poikelin@qt.io>2021-12-30 10:41:42 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-12 07:37:37 +0000
commit56c8629a24a1333ed4ae7b58019ecabef157d3bf (patch)
treec86e925f6416e1e4cdb418f99a83a518069e83ca
parentf72e682579f1a6eb1304d73a8a05702f1e0fbc88 (diff)
Fix setting of socket options
Socket options need to be set after connectToHost() to take any effect. Change-Id: I006a8c59ba1c78d5edaa77d545bb0f640b7224fe Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 647922b1122977625b8f32fbc0bb2e9339afb4a3) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/websockets/qwebsocket_p.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp
index 62d53c5..ef9b247 100644
--- a/src/websockets/qwebsocket_p.cpp
+++ b/src/websockets/qwebsocket_p.cpp
@@ -448,8 +448,10 @@ void QWebSocketPrivate::open(const QNetworkRequest &request, bool mask)
QSslSocket *sslSocket = new QSslSocket(q);
m_pSocket = sslSocket;
if (Q_LIKELY(m_pSocket)) {
- m_pSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
- m_pSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
+ QObject::connect(sslSocket, &QSslSocket::connected, [sslSocket](){
+ sslSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
+ sslSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
+ });
m_pSocket->setReadBufferSize(m_readBufferSize);
m_pSocket->setPauseMode(m_pauseMode);
@@ -477,8 +479,10 @@ void QWebSocketPrivate::open(const QNetworkRequest &request, bool mask)
if (url.scheme() == QStringLiteral("ws")) {
m_pSocket = new QTcpSocket(q);
if (Q_LIKELY(m_pSocket)) {
- m_pSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
- m_pSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
+ QObject::connect(m_pSocket, &QTcpSocket::connected, [this](){
+ m_pSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
+ m_pSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
+ });
m_pSocket->setReadBufferSize(m_readBufferSize);
m_pSocket->setPauseMode(m_pauseMode);