aboutsummaryrefslogtreecommitdiff
path: root/src/NeoRuntimeManager
diff options
context:
space:
mode:
authorJakob Stendahl <jakobste@uio.no>2021-10-06 17:25:41 +0200
committerJakob Stendahl <jakobste@uio.no>2021-10-06 17:25:41 +0200
commitfab520ff90e3fb5ca877cf3ab8b3ced847ec30fb (patch)
tree6d1f61170409b6004e77d9016a22ac9fe7792eee /src/NeoRuntimeManager
parentd962cdaa317b384b2e82d0f9dc5b9d15a5733869 (diff)
downloadLuxcena-Neo-fab520ff90e3fb5ca877cf3ab8b3ced847ec30fb.tar.gz
Luxcena-Neo-fab520ff90e3fb5ca877cf3ab8b3ced847ec30fb.zip
:art: Only allocate a buffer of the size needed, instead of always 128 bit
Diffstat (limited to 'src/NeoRuntimeManager')
-rw-r--r--src/NeoRuntimeManager/IPC.js16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/NeoRuntimeManager/IPC.js b/src/NeoRuntimeManager/IPC.js
index d50d335..281a633 100644
--- a/src/NeoRuntimeManager/IPC.js
+++ b/src/NeoRuntimeManager/IPC.js
@@ -121,27 +121,33 @@ class IPC {
* for such events. */
sendCommand(commandType, name, value) {
if (this.connected) {
- let buf = Buffer.allocUnsafe(128); // It's fine, we know what we are doing
- // let buf = Buffer.alloc(128);
+ let buf;
switch (commandType) {
case (COMMAND.SET_GLOB):
+ buf = Buffer.allocUnsafe(3);
buf[1] = name;
buf[2] = value;
break;
+
case (COMMAND.SET_VAR):
if (name.length > 32) { return {success: false, reason: "name too long", detail: "max size of name is 32 bytes"}; }
- if (name.length > 93) { return {success: false, reason: "value too long", detail: "max size of value is 93 bytes"}; }
+ if (value.length > 93) { return {success: false, reason: "value too long", detail: "max size of value is 93 bytes"}; }
+ buf = Buffer.allocUnsafe(3 + name.length + value.length);
buf[1] = name.length;
buf[2] = value.length;
buf.write(name, 3, name.length, "ascii");
buf.write(value, 3+name.length, value.length, "ascii");
break;
+
case (COMMAND.SET_SEND_STRIP_BUF):
+ buf = Buffer.allocUnsafe(2);
buf[1] = (name) ? 1 : 0;
+ break;
+
default:
- logger.info(`IPC UNKNOWN COMMANDTYPE ${commandType}`)
- return;
+ logger.warning(`IPC UNKNOWN COMMANDTYPE ${commandType}`)
+ return {success: false, reason: "ipc command unknown", detail: commandType};
}
buf[0] = commandType;