Skip to content

Commit 814cd72

Browse files
committed
handle sending forced messages of non-multiple-of-4 sizes
1 parent 4804ea9 commit 814cd72

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/library.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6827,7 +6827,10 @@ LibraryManager.library = {
68276827
console.log('opening ws://' + info.host + ':' + info.port);
68286828
info.socket = new WebSocket('ws://' + info.host + ':' + info.port, ['binary']);
68296829
info.socket.binaryType = 'arraybuffer';
6830-
info.buffer = new Uint8Array(Sockets.BUFFER_SIZE);
6830+
6831+
var i32Temp = new Uint32Array(1);
6832+
var i8Temp = new Uint8Array(i32Temp.buffer);
6833+
68316834
info.inQueue = [];
68326835
info.socket.onmessage = function(event) {
68336836
assert(typeof event.data !== 'string' && event.data.byteLength); // must get binary data!
@@ -6836,10 +6839,10 @@ LibraryManager.library = {
68366839
Module.print(['onmessage', data.length, '|', Array.prototype.slice.call(data)]);
68376840
#endif
68386841
#if SOCKET_FORCED_MESSAGING
6839-
var i32View = new Uint32Array(data.buffer);
68406842
var start = 0;
6841-
while (start < data.length) {
6842-
var currLen = i32View[start>>2];
6843+
while (start+4 < data.length) {
6844+
i8Temp.set(data.subarray(start, start+4));
6845+
var currLen = i32Temp[0];
68436846
assert(currLen > 0);
68446847
start += 4;
68456848
assert(start + currLen <= data.length, [data.length, start, currLen]); // must not receive fractured messages!
@@ -6884,8 +6887,8 @@ LibraryManager.library = {
68846887
info.sender = function(data) {
68856888
#if SOCKET_FORCED_MESSAGING
68866889
var buffer = new Uint8Array(data.length+4);
6887-
var i32View = new Uint32Array(buffer.buffer);
6888-
i32View[0] = data.length;
6890+
i32Temp[0] = data.length;
6891+
buffer.set(i8Temp);
68896892
buffer.set(data, 4);
68906893
outQueue.push(buffer);
68916894
#else

0 commit comments

Comments
 (0)