Skip to content

Commit 539a197

Browse files
authored
[library_sockfs.js] Cleanup buffer handling in sendmsg (#22987)
1 parent b3edd4c commit 539a197

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/library_sockfs.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -619,16 +619,13 @@ addToLibrary({
619619
buffer = buffer.buffer;
620620
}
621621

622-
var data;
623-
#if PTHREADS
624-
// WebSockets .send() does not allow passing a SharedArrayBuffer, so clone the portion of the SharedArrayBuffer as a regular
625-
// ArrayBuffer that we want to send.
626-
if (buffer instanceof SharedArrayBuffer) {
627-
data = new Uint8Array(new Uint8Array(buffer.slice(offset, offset + length))).buffer;
628-
} else {
629-
#endif
630-
data = buffer.slice(offset, offset + length);
622+
var data = buffer.slice(offset, offset + length);
631623
#if PTHREADS
624+
// WebSockets .send() does not allow passing a SharedArrayBuffer, so
625+
// clone the the SharedArrayBuffer as regular ArrayBuffer before
626+
// sending.
627+
if (data instanceof SharedArrayBuffer) {
628+
data = new Uint8Array(new Uint8Array(data)).buffer;
632629
}
633630
#endif
634631

test/test_sockets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ def test_enet(self):
285285
'native': [WebsockifyServerHarness, 59160, ['-DTEST_DGRAM=0']],
286286
'tcp': [CompiledServerHarness, 59162, ['-DTEST_DGRAM=0']],
287287
'udp': [CompiledServerHarness, 59164, ['-DTEST_DGRAM=1']],
288+
'pthread': [CompiledServerHarness, 59165, ['-pthread', '-sPROXY_TO_PTHREAD']],
288289
})
289290
def test_nodejs_sockets_echo(self, harness_class, port, args):
290291
if harness_class == WebsockifyServerHarness and common.EMTEST_LACKS_NATIVE_CLANG:

0 commit comments

Comments
 (0)