From ede0665cb83d52a8ce8c471fa1cfff167f14b599 Mon Sep 17 00:00:00 2001 From: Justin Head Date: Sat, 19 Nov 2016 14:18:11 -0600 Subject: [PATCH 01/14] Update package.json --- package.json | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 518347b..bd13c30 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,33 @@ { "name": "svmq", - "version": "1.0.2", - "description": "Native System V (svipc) message queues in Node.js", + "version": "1.0.3", + "description": "Native System V message queues in Node.js", "main": "index.js", "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", "install": "node-gyp rebuild" }, - "author": "", + "repository": { + "type": "git", + "url": "git+https://github.com/jhead/node-svmq.git" + }, + "keywords": [ + "system", + "v", + "sysv", + "mq", + "message", + "queue", + "svmq", + "ipc" + ], + "author": "Justin Head ", "license": "MIT", + "gypfile": true, + "bugs": { + "url": "https://github.com/jhead/node-svmq/issues" + }, + "homepage": "https://github.com/jhead/node-svmq#readme", "dependencies": { "nan": "^2.2.0" } From 693bba761539ec3799ee43bbb08b65ba9f37db26 Mon Sep 17 00:00:00 2001 From: Justin Head Date: Fri, 16 Dec 2016 12:01:54 -0600 Subject: [PATCH 02/14] Avoid struct name collision on Linux --- src/functions.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/functions.cc b/src/functions.cc index 81a0c4a..b1baf7f 100644 --- a/src/functions.cc +++ b/src/functions.cc @@ -12,12 +12,11 @@ using Nan::Callback; using Nan::New; using Nan::Null; -#ifndef __USE_GNU - #ifndef MSGMAX #define MSGMAX 4056 #endif +#ifndef linux struct msgbuf { long mtype; char mtext[MSGMAX - 4]; From 197bcd36fd7703f07d22f8a6b9237e1ae43b0664 Mon Sep 17 00:00:00 2001 From: Justin Head Date: Fri, 16 Dec 2016 12:09:25 -0600 Subject: [PATCH 03/14] 1.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bd13c30..4b56cf8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svmq", - "version": "1.0.3", + "version": "1.0.4", "description": "Native System V message queues in Node.js", "main": "index.js", "scripts": { From fb6eb275e10c49632d1058d2e54b6b36f8ba5d71 Mon Sep 17 00:00:00 2001 From: Justin Head Date: Wed, 3 May 2017 11:37:12 -0500 Subject: [PATCH 04/14] Memory fixes for #1 --- src/functions.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/functions.cc b/src/functions.cc index b1baf7f..92a4363 100644 --- a/src/functions.cc +++ b/src/functions.cc @@ -19,7 +19,7 @@ using Nan::Null; #ifndef linux struct msgbuf { long mtype; - char mtext[MSGMAX - 4]; + char mtext[1]; }; #endif @@ -43,13 +43,16 @@ class SendMessageWorker : public AsyncWorker { ~SendMessageWorker() { } void Execute() { - msgbuf *message = new msgbuf; - message->mtype = type; + struct msgbuf* message = + (struct msgbuf*)malloc(sizeof(struct msgbuf) + dataLength); + message->mtype = type; memcpy(message->mtext, data, dataLength); ret = msgsnd(id, message, dataLength, flags); error = errno; + + free(message); } void HandleOKCallback () { From 7d99f3dc5ee87950bd5c17d1e0ae8a62faa1da3e Mon Sep 17 00:00:00 2001 From: Justin Head Date: Thu, 4 May 2017 10:43:54 -0500 Subject: [PATCH 05/14] Additional fixes for #1 Thanks to @bvandergiessen --- src/functions.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/functions.cc b/src/functions.cc index 92a4363..ae2a468 100644 --- a/src/functions.cc +++ b/src/functions.cc @@ -23,6 +23,8 @@ struct msgbuf { }; #endif +const size_t bsize = sizeof(struct msgbuf); + const char *ConcatString(std::string one, const char *two) { return one.append(two).c_str(); } @@ -44,7 +46,7 @@ class SendMessageWorker : public AsyncWorker { void Execute() { struct msgbuf* message = - (struct msgbuf*)malloc(sizeof(struct msgbuf) + dataLength); + (struct msgbuf*)malloc(bsize + dataLength); message->mtype = type; memcpy(message->mtext, data, dataLength); @@ -68,7 +70,7 @@ class SendMessageWorker : public AsyncWorker { private: int id; char *data; - int dataLength; + size_t dataLength; long type; int flags; int ret; @@ -84,7 +86,8 @@ class ReceiveMessageWorker : public AsyncWorker { ~ReceiveMessageWorker() { } void Execute() { - message = new msgbuf; + struct msgbuf* message = + (struct msgbuf*)malloc(bsize + bufferLength); bufferLength = msgrcv(id, message, bufferLength, type, flags); error = errno; @@ -174,7 +177,7 @@ NAN_METHOD(SendMessage) { int id = info[0]->Int32Value(); char* bufferData = node::Buffer::Data(info[1]); size_t bufferLength = (size_t) node::Buffer::Length(info[1]); - long type = info[2]->Int32Value(); + long type = (long) info[2]->Int32Value(); int flags = info[3]->Int32Value(); Callback *callback = new Callback(info[4].As()); @@ -184,7 +187,7 @@ NAN_METHOD(SendMessage) { NAN_METHOD(ReceiveMessage) { int id = info[0]->Int32Value(); size_t bufferLength = (size_t) info[1]->Int32Value(); - long type = info[2]->Int32Value(); + long type = (long) info[2]->Int32Value(); int flags = info[3]->Int32Value(); Callback *callback = new Callback(info[4].As()); From 49ce589a27f4c269999bef60e5746d6380fc267c Mon Sep 17 00:00:00 2001 From: Justin Head Date: Thu, 4 May 2017 10:49:02 -0500 Subject: [PATCH 06/14] v1.0.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4b56cf8..0b4a2de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svmq", - "version": "1.0.4", + "version": "1.0.5", "description": "Native System V message queues in Node.js", "main": "index.js", "scripts": { From 828479484d48c796c6c966e63195e1b51c9b4a85 Mon Sep 17 00:00:00 2001 From: Justin Head Date: Mon, 8 May 2017 11:04:20 -0500 Subject: [PATCH 07/14] Fix incorrect declaration, add free() --- src/functions.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/functions.cc b/src/functions.cc index ae2a468..3e35331 100644 --- a/src/functions.cc +++ b/src/functions.cc @@ -86,8 +86,8 @@ class ReceiveMessageWorker : public AsyncWorker { ~ReceiveMessageWorker() { } void Execute() { - struct msgbuf* message = - (struct msgbuf*)malloc(bsize + bufferLength); + message = + (struct msgbuf*) malloc(bsize + bufferLength); bufferLength = msgrcv(id, message, bufferLength, type, flags); error = errno; @@ -105,12 +105,14 @@ class ReceiveMessageWorker : public AsyncWorker { argv[1] = Nan::CopyBuffer(message->mtext, bufferLength).ToLocalChecked(); } + free(message); + callback->Call(2, argv); } private: int id; - msgbuf *message; + struct msgbuf* message; size_t bufferLength; long type; int flags; From db743683b8d8c1df6a67c30e3d0aa0b05d664b31 Mon Sep 17 00:00:00 2001 From: Justin Head Date: Mon, 15 May 2017 10:10:04 -0500 Subject: [PATCH 08/14] v1.0.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0b4a2de..53f1636 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svmq", - "version": "1.0.5", + "version": "1.0.6", "description": "Native System V message queues in Node.js", "main": "index.js", "scripts": { From 2347f8fb586eca2726f1f933b14d4a8ddef1c7b3 Mon Sep 17 00:00:00 2001 From: Kim Nyholm Date: Tue, 24 Sep 2019 14:43:55 +0000 Subject: [PATCH 09/14] Fix deprecated Int32Value for node12 --- src/functions.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/functions.cc b/src/functions.cc index 3e35331..31f1fba 100644 --- a/src/functions.cc +++ b/src/functions.cc @@ -120,8 +120,8 @@ class ReceiveMessageWorker : public AsyncWorker { }; NAN_METHOD(GetMessageQueue) { - key_t key = (key_t) info[0]->Int32Value(); - int flags = info[1]->Int32Value(); + key_t key = (key_t) info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); + int flags = info[1]->Int32Value(Nan::GetCurrentContext()).FromJust(); int queue = msgget(key, flags); @@ -133,8 +133,8 @@ NAN_METHOD(GetMessageQueue) { } NAN_METHOD(ControlMessageQueue) { - int id = info[0]->Int32Value(); - int cmd = info[1]->Int32Value(); + int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); + int cmd = info[1]->Int32Value(Nan::GetCurrentContext()).FromJust(); msqid_ds *buf; @@ -164,7 +164,7 @@ NAN_METHOD(ControlMessageQueue) { } NAN_METHOD(CloseMessageQueue) { - int id = info[0]->Int32Value(); + int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); int ret = msgctl(id, IPC_RMID, nullptr); @@ -176,21 +176,21 @@ NAN_METHOD(CloseMessageQueue) { } NAN_METHOD(SendMessage) { - int id = info[0]->Int32Value(); + int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); char* bufferData = node::Buffer::Data(info[1]); size_t bufferLength = (size_t) node::Buffer::Length(info[1]); - long type = (long) info[2]->Int32Value(); - int flags = info[3]->Int32Value(); + long type = (long) info[2]->Int32Value(Nan::GetCurrentContext()).FromJust(); + int flags = info[3]->Int32Value(Nan::GetCurrentContext()).FromJust(); Callback *callback = new Callback(info[4].As()); AsyncQueueWorker(new SendMessageWorker(callback, id, bufferData, bufferLength, type, flags)); } NAN_METHOD(ReceiveMessage) { - int id = info[0]->Int32Value(); - size_t bufferLength = (size_t) info[1]->Int32Value(); - long type = (long) info[2]->Int32Value(); - int flags = info[3]->Int32Value(); + int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); + size_t bufferLength = (size_t) info[1]->Int32Value(Nan::GetCurrentContext()).FromJust(); + long type = (long) info[2]->Int32Value(Nan::GetCurrentContext()).FromJust(); + int flags = info[3]->Int32Value(Nan::GetCurrentContext()).FromJust(); Callback *callback = new Callback(info[4].As()); AsyncQueueWorker(new ReceiveMessageWorker(callback, id, bufferLength, type, flags)); From 52af4f80a55346b4afa2f8e5fcc283140b49333a Mon Sep 17 00:00:00 2001 From: Kim Nyholm Date: Tue, 24 Sep 2019 20:55:27 +0100 Subject: [PATCH 10/14] Use shorter nan syntax --- src/functions.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/functions.cc b/src/functions.cc index 31f1fba..1161e62 100644 --- a/src/functions.cc +++ b/src/functions.cc @@ -120,8 +120,8 @@ class ReceiveMessageWorker : public AsyncWorker { }; NAN_METHOD(GetMessageQueue) { - key_t key = (key_t) info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); - int flags = info[1]->Int32Value(Nan::GetCurrentContext()).FromJust(); + key_t key = (key_t) Nan::To(info[0]).FromJust(); + int flags = Nan::To(info[1]).FromJust(); int queue = msgget(key, flags); @@ -133,8 +133,8 @@ NAN_METHOD(GetMessageQueue) { } NAN_METHOD(ControlMessageQueue) { - int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); - int cmd = info[1]->Int32Value(Nan::GetCurrentContext()).FromJust(); + int id = Nan::To(info[0]).FromJust(); + int cmd = Nan::To(info[1]).FromJust(); msqid_ds *buf; @@ -164,7 +164,7 @@ NAN_METHOD(ControlMessageQueue) { } NAN_METHOD(CloseMessageQueue) { - int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); + int id = Nan::To(info[0]).FromJust(); int ret = msgctl(id, IPC_RMID, nullptr); @@ -176,21 +176,21 @@ NAN_METHOD(CloseMessageQueue) { } NAN_METHOD(SendMessage) { - int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); + int id = Nan::To(info[0]).FromJust(); char* bufferData = node::Buffer::Data(info[1]); size_t bufferLength = (size_t) node::Buffer::Length(info[1]); - long type = (long) info[2]->Int32Value(Nan::GetCurrentContext()).FromJust(); - int flags = info[3]->Int32Value(Nan::GetCurrentContext()).FromJust(); + long type = (long) Nan::To(info[2]).FromJust(); + int flags = Nan::To(info[3]).FromJust(); Callback *callback = new Callback(info[4].As()); AsyncQueueWorker(new SendMessageWorker(callback, id, bufferData, bufferLength, type, flags)); } NAN_METHOD(ReceiveMessage) { - int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust(); - size_t bufferLength = (size_t) info[1]->Int32Value(Nan::GetCurrentContext()).FromJust(); - long type = (long) info[2]->Int32Value(Nan::GetCurrentContext()).FromJust(); - int flags = info[3]->Int32Value(Nan::GetCurrentContext()).FromJust(); + int id = Nan::To(info[0]).FromJust(); + size_t bufferLength = (size_t) Nan::To(info[1]).FromJust(); + long type = (long) Nan::To(info[2]).FromJust(); + int flags = Nan::To(info[3]).FromJust(); Callback *callback = new Callback(info[4].As()); AsyncQueueWorker(new ReceiveMessageWorker(callback, id, bufferLength, type, flags)); From 840a39b31ec6774795a7fc959a1bbaa4d861dcc1 Mon Sep 17 00:00:00 2001 From: Justin Head Date: Mon, 7 Oct 2019 07:46:36 -0700 Subject: [PATCH 11/14] v1.0.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 53f1636..54bdf31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svmq", - "version": "1.0.6", + "version": "1.0.7", "description": "Native System V message queues in Node.js", "main": "index.js", "scripts": { From 033fbfdaefd900bbe5520542180b978705e03738 Mon Sep 17 00:00:00 2001 From: Justin Head Date: Sat, 12 Sep 2020 13:07:31 -0700 Subject: [PATCH 12/14] Fix missing arg in example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7aea750..2111bcd 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ var MSGMAX = svmq.MSGMAX; // max message data size (hardcoded) var id = msg.get(31337, 950); // Push a string to the queue -msg.snd(id, new Buffer('TestString1234'), 1, (err) => { +msg.snd(id, new Buffer('TestString1234'), 1, 0, (err) => { if (err) throw err; }); From 6293609adabf534e8e0015b2f7f59dd72b77b573 Mon Sep 17 00:00:00 2001 From: Justin Head Date: Sat, 12 Sep 2020 13:07:41 -0700 Subject: [PATCH 13/14] Add a quick unit test --- package.json | 5 ++++- spec/queueSpec.js | 32 ++++++++++++++++++++++++++++++++ spec/support/jasmine.json | 11 +++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 spec/queueSpec.js create mode 100644 spec/support/jasmine.json diff --git a/package.json b/package.json index 54bdf31..6016468 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Native System V message queues in Node.js", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", + "test": "jasmine spec/**/*.js", "install": "node-gyp rebuild" }, "repository": { @@ -30,5 +30,8 @@ "homepage": "https://github.com/jhead/node-svmq#readme", "dependencies": { "nan": "^2.2.0" + }, + "devDependencies": { + "jasmine": "^3.6.1" } } diff --git a/spec/queueSpec.js b/spec/queueSpec.js new file mode 100644 index 0000000..4743483 --- /dev/null +++ b/spec/queueSpec.js @@ -0,0 +1,32 @@ +const MessageQueue = require('../'); + +const inputs = [ + Buffer.alloc(0), + Buffer.from(""), + Buffer.from("test"), + Buffer.from("test 1234 foo bar 567890"), + Buffer.from([1, 2, 3, 4]), + Buffer.from(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])), + Buffer.alloc(1024) +]; + +describe("MessageQueue", function () { + + // Test a batch of diverse inputs that should be supported + inputs.forEach((input, index) =>{ + const msgType = index + 1; + const selectedInput = input; + + it("push and pop a message: " + selectedInput, function (done) { + const queue = new MessageQueue(31337); + + queue.push(selectedInput, { type: msgType }) + queue.pop({ type: msgType }, function(err, msg) { + expect(err).toBeNull(); + expect(msg).toEqual(selectedInput); + done(); + }) + }); + }) + +}); \ No newline at end of file diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json new file mode 100644 index 0000000..370fc44 --- /dev/null +++ b/spec/support/jasmine.json @@ -0,0 +1,11 @@ +{ + "spec_dir": "spec", + "spec_files": [ + "**/*[sS]pec.js" + ], + "helpers": [ + "helpers/**/*.js" + ], + "stopSpecOnExpectationFailure": false, + "random": true +} From e4e357c379e2a78eb3b245322ab06b6568056d37 Mon Sep 17 00:00:00 2001 From: Justin Head Date: Sat, 12 Sep 2020 13:15:46 -0700 Subject: [PATCH 14/14] Add workflow to run tests (#7) --- .github/workflows/node.js.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/node.js.yml diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000..799c4d0 --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,28 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [8.x, 10.x, 12.x, 14.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test