wasm: fix wasm sockets when data buffer is less than 3696

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 <lorn.potter@qt.io>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 9b01f1bdb7e4107de3f898446fa087efa81e029e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Lorn Potter 2024-06-17 15:38:09 +10:00 committed by Qt Cherry-pick Bot
parent 1619b7232e
commit b56e959d60

View File

@ -8,6 +8,7 @@
#include <QtCore/qthread.h>
#include <QtCore/qsocketnotifier.h>
#include <QtCore/private/qstdweb_p.h>
#include <sys/ioctl.h>
#include "emscripten.h"
#include <emscripten/html5.h>
@ -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)