From b56e959d600c7f8ea6a9e785b76f023ed027a388 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Mon, 17 Jun 2024 15:38:09 +1000 Subject: [PATCH] wasm: fix wasm sockets when data buffer is less than 3696 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The socket message comes in too early so add an additional postEvent when registering the socket notifier. Fixes: QTBUG-125874 Change-Id: Ie951b7a1b858d12927478e071157780ac4fc320b Reviewed-by: Lorn Potter Reviewed-by: Morten Johan Sørvig Reviewed-by: Mårten Nordheim (cherry picked from commit 9b01f1bdb7e4107de3f898446fa087efa81e029e) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qeventdispatcher_wasm.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp index e1ec858ef04..d9f234d4192 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm.cpp +++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "emscripten.h" #include @@ -337,6 +338,14 @@ void QEventDispatcherWasm::registerSocketNotifier(QSocketNotifier *notifier) g_socketNotifiers.insert({notifier->socket(), notifier}); if (wasEmpty) runOnMainThread([] { setEmscriptenSocketCallbacks(); }); + + int count; + ioctl(notifier->socket(), FIONREAD, &count); + + // message may have arrived already + if (count > 0 && notifier->type() == QSocketNotifier::Read) { + QCoreApplication::postEvent(notifier, new QEvent(QEvent::SockAct)); + } } void QEventDispatcherWasm::unregisterSocketNotifier(QSocketNotifier *notifier)