Skip to content

Commit d1530e7

Browse files
authored
Fix websocket in shared memory environment (#19247)
1 parent 1386520 commit d1530e7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/library_websocket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ var LibraryWebSocket = {
347347

348348
dbg('emscripten_websocket_send_binary(socketId='+socketId+',binaryData='+binaryData+ ',dataLength='+dataLength+'), ' + s);
349349
#endif
350-
#if PTHREADS
350+
#if SHARED_MEMORY
351351
// TODO: This is temporary to cast a shared Uint8Array to a non-shared Uint8Array. This could be removed if WebSocket API is improved
352352
// to allow passing in views to SharedArrayBuffers
353353
socket.send(new Uint8Array({{{ makeHEAPView('U8', 'binaryData', 'binaryData+dataLength') }}}));

test/test_sockets.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,14 @@ def test_nodejs_sockets_echo_subprotocol(self):
325325

326326
# Test Emscripten WebSockets API to send and receive text and binary messages against an echo server.
327327
# N.B. running this test requires 'npm install ws' in Emscripten root directory
328-
def test_websocket_send(self):
328+
# NOTE: Shared buffer is not allowed for websocket sending.
329+
@parameterized({
330+
'': [[]],
331+
'shared': [['-sSHARED_MEMORY']],
332+
})
333+
def test_websocket_send(self, args):
329334
with NodeJsWebSocketEchoServerProcess():
330-
self.btest_exit(test_file('websocket/test_websocket_send.c'), args=['-lwebsocket', '-sNO_EXIT_RUNTIME', '-sWEBSOCKET_DEBUG'])
335+
self.btest_exit(test_file('websocket/test_websocket_send.c'), args=['-lwebsocket', '-sNO_EXIT_RUNTIME', '-sWEBSOCKET_DEBUG'] + args)
331336

332337
# Test that native POSIX sockets API can be used by proxying calls to an intermediate WebSockets
333338
# -> POSIX sockets bridge server

0 commit comments

Comments
 (0)