diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2022-01-27 16:15:57 +0100 |
---|---|---|
committer | Morten Sørvig <morten.sorvig@qt.io> | 2022-06-02 23:54:46 +0200 |
commit | 18f0793f9cc23042fe78efe2a3dcc8e6e9a90ccf (patch) | |
tree | c8ec9c5eb16358c86fa686ba83ffe3aec0dc23ff /src/network/socket | |
parent | 6376b1c5a708ddb1a82e81cbc7ce4df159ba565b (diff) |
wasm: add support for blocking sockets
Add support for blocking sockets on secondary threads and on the main
thread with asyncify. This extends the support for websockify tunneled
TCP sockets, which was previously limited to async sockets on the main
thread.
Blocking sockets support is implemented by emulating select() on top
of emscripten's socket notification support. This is requires synchronization
between the blockee threads and the main thread, since we get socket
notification callbacks on the main thread. The synchronized state is held
in g_socketState where the main thread registers socket readiness state and
blocking threads register themselves.
Blocking using asyncify on the main thread is similar to blocking on
a secondary thread, with the exception that the main thread suspends
with qt_asyncify_suspend() instead of waiting on a wait condition.
Change-Id: Idb5a493644e1e6634057dc2f64f2e99e82e3c01e
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src/network/socket')
-rw-r--r-- | src/network/socket/qnativesocketengine_unix.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp index dfa18849a1..2c2ea706e5 100644 --- a/src/network/socket/qnativesocketengine_unix.cpp +++ b/src/network/socket/qnativesocketengine_unix.cpp @@ -11,6 +11,9 @@ #include "qvarlengtharray.h" #include "qnetworkinterface.h" #include "qendian.h" +#ifdef Q_OS_WASM +#include <private/qeventdispatcher_wasm_p.h> +#endif #include <time.h> #include <errno.h> #include <fcntl.h> @@ -1353,6 +1356,8 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool selectForRead) co return nativeSelect(timeout, selectForRead, !selectForRead, &dummy, &dummy); } +#ifndef Q_OS_WASM + int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool checkWrite, bool *selectForRead, bool *selectForWrite) const { @@ -1383,4 +1388,24 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool c return ret; } +#else + +int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool checkWrite, + bool *selectForRead, bool *selectForWrite) const +{ + *selectForRead = checkRead; + *selectForWrite = checkWrite; + bool socketDisconnect = false; + QEventDispatcherWasm::socketSelect(timeout, socketDescriptor, checkRead, checkWrite,selectForRead, selectForWrite, &socketDisconnect); + + // The disconnect/close handling code in QAbstractsScket::canReadNotification() + // does not detect remote disconnect properly; do that here as a workardound. + if (socketDisconnect) + receiver->closeNotification(); + + return 1; +} + +#endif // Q_OS_WASM + QT_END_NAMESPACE |