do not use two char message marker, since it can be splitted

pull/198/merge
nightwing 2017-04-06 23:14:34 +00:00
rodzic b20b08663d
commit 2eb1a76a93
1 zmienionych plików z 6 dodań i 6 usunięć

Wyświetl plik

@ -2821,7 +2821,7 @@ function createServer() {
return; return;
msg.command = msg.command || "vfs-collab"; msg.command = msg.command || "vfs-collab";
var strMsg = JSON.stringify(msg); var strMsg = JSON.stringify(msg);
client.write(strMsg + "\0\0"); client.write(strMsg + "\0");
}; };
client.on("data", function handShake(data) { client.on("data", function handShake(data) {
@ -2855,12 +2855,12 @@ function createServer() {
data = data.toString(); data = data.toString();
var idx; var idx;
while (true) { while (true) {
idx = data.indexOf("\0\0"); idx = data.indexOf("\0");
if (idx === -1) if (idx === -1)
return data && buff.push(data); return data && buff.push(data);
buff.push(data.substring(0, idx)); buff.push(data.substring(0, idx));
var clientMsg = buff.join(""); var clientMsg = buff.join("");
data = data.substring(idx + 2); data = data.substring(idx + 1);
buff = []; buff = [];
client.emit("message", clientMsg); client.emit("message", clientMsg);
} }
@ -3008,12 +3008,12 @@ function initSocket(userIds, callback) {
data = data.toString(); data = data.toString();
var idx; var idx;
while (true) { while (true) {
idx = data.indexOf("\0\0"); idx = data.indexOf("\0");
if (idx === -1) if (idx === -1)
return buff.push(data); return buff.push(data);
buff.push(data.substring(0, idx)); buff.push(data.substring(0, idx));
var streamData = buff.join(""); var streamData = buff.join("");
data = data.substring(idx + 2); data = data.substring(idx + 1);
buff = []; buff = [];
stream.emit("data", streamData); stream.emit("data", streamData);
} }
@ -3110,7 +3110,7 @@ var exports = module.exports = function(vfs, options, register) {
// logVerbose("[vfs-collab] IN-STREAM", msg); // logVerbose("[vfs-collab] IN-STREAM", msg);
var client = vfsClientMap[clientId]; var client = vfsClientMap[clientId];
if (client) if (client)
client.write(JSON.stringify(msg) + "\0\0"); client.write(JSON.stringify(msg) + "\0");
} }
function dispose(clientId) { function dispose(clientId) {