Skip to content
This repository was archived by the owner on Apr 24, 2020. It is now read-only.

Commit 4df3e56

Browse files
author
Ron Korving
committed
Exposed zmq.socketOptionExists and zmq.socketTypeExists
More style fixes
1 parent ac501a5 commit 4df3e56

25 files changed

+269
-284
lines changed

binding.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,11 +1279,6 @@ namespace zmq {
12791279
Local<Object> options = Nan::New<Object>();
12801280
Local<Object> ctxOptions = Nan::New<Object>();
12811281

1282-
Nan::Set(target, Nan::New("sendFlags").ToLocalChecked(), sendFlags);
1283-
Nan::Set(target, Nan::New("types").ToLocalChecked(), types);
1284-
Nan::Set(target, Nan::New("options").ToLocalChecked(), options);
1285-
Nan::Set(target, Nan::New("ctxOptions").ToLocalChecked(), ctxOptions);
1286-
12871282
// Helper macros for storing and exposing constants
12881283

12891284
#define OPT(type, name) \
@@ -1720,7 +1715,12 @@ namespace zmq {
17201715
#undef SENDFLAG
17211716
#undef TYPE
17221717

1723-
// Expose methods
1718+
// Expose properties and methods
1719+
1720+
Nan::Set(target, Nan::New("sendFlags").ToLocalChecked(), sendFlags);
1721+
Nan::Set(target, Nan::New("types").ToLocalChecked(), types);
1722+
Nan::Set(target, Nan::New("options").ToLocalChecked(), options);
1723+
Nan::Set(target, Nan::New("ctxOptions").ToLocalChecked(), ctxOptions);
17241724

17251725
Nan::SetMethod(target, "zmqVersion", ZmqVersion);
17261726
#if ZMQ_VERSION_MAJOR >= 4

lib/index.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ exports.version = zmq.zmqVersion();
2424

2525
exports.curveKeypair = zmq.zmqCurveKeypair;
2626

27-
/**
28-
* Expose socket types.
29-
*/
30-
31-
exports.types = socket.types;
32-
3327
/**
3428
* Context creation
29+
*
30+
* @return {Context}
3531
*/
3632

3733
exports.context = exports.createContext = function (options) {
@@ -40,6 +36,8 @@ exports.context = exports.createContext = function (options) {
4036

4137
/**
4238
* Exposing the default context
39+
*
40+
* @return {Context}
4341
*/
4442

4543
exports.getDefaultContext = function () {
@@ -48,12 +46,34 @@ exports.getDefaultContext = function () {
4846

4947
/**
5048
* Socket creation, using a default context
49+
*
50+
* @return {Socket}
5151
*/
5252

5353
exports.socket = exports.createSocket = function (type, options) {
5454
return socket.createSocket(type, options, context.getDefaultContext());
5555
};
5656

57+
/**
58+
* Tests if an option exists in this version of ZMQ
59+
*
60+
* @return {Boolean}
61+
*/
62+
63+
exports.socketOptionExists = function (option) {
64+
return socket.opts.hasOwnProperty(option);
65+
};
66+
67+
/**
68+
* Tests if a socket type exists in this version of ZMQ
69+
*
70+
* @return {Boolean}
71+
*/
72+
73+
exports.socketTypeExists = function (type) {
74+
return socket.types.hasOwnProperty(type);
75+
};
76+
5777
/**
5878
* JS proxy method based on API characteristics of the native zmq_proxy()
5979
*/

lib/socket.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ var events = exports.events = {
7272
*
7373
* @constructor
7474
* @param {String|Number} type
75-
* @api public
7675
*/
7776

7877
function Socket(type, ctx) {
@@ -116,7 +115,6 @@ util.inherits(Socket, EventEmitter);
116115
* all send() calls will be queued
117116
*
118117
* @return {Socket} for chaining
119-
* @api public
120118
*/
121119

122120
Socket.prototype.pause = function () {
@@ -128,7 +126,6 @@ Socket.prototype.pause = function () {
128126
* Set a socket back to normal work mode
129127
*
130128
* @return {Socket} for chaining
131-
* @api public
132129
*/
133130

134131
Socket.prototype.resume = function () {
@@ -142,7 +139,6 @@ Socket.prototype.resume = function () {
142139
* Manually read from a socket, even when paused
143140
*
144141
* @return {undefined|Buffer[]} An array of message parts, or undefined if there was nothing in the queue
145-
* @api public
146142
*/
147143

148144
Socket.prototype.read = function () {
@@ -152,7 +148,7 @@ Socket.prototype.read = function () {
152148
/**
153149
* Bump the reference count on the socket
154150
*
155-
* @api public
151+
* @return {Socket} for chaining
156152
*/
157153

158154
Socket.prototype.ref = function () {
@@ -163,7 +159,7 @@ Socket.prototype.ref = function () {
163159
/**
164160
* Lower the reference count on the socket
165161
*
166-
* @api public
162+
* @return {Socket} for chaining
167163
*/
168164

169165
Socket.prototype.unref = function () {
@@ -178,7 +174,6 @@ Socket.prototype.unref = function () {
178174
* @param {String} opt
179175
* @param {Number|String|Buffer} val
180176
* @return {Socket} for chaining
181-
* @api public
182177
*/
183178

184179
Socket.prototype.set = function (opt, val) {
@@ -197,7 +192,6 @@ Socket.prototype.setsockopt = Socket.prototype.set;
197192
*
198193
* @param {String} opt
199194
* @return {Number|String|Buffer}
200-
* @api public
201195
*/
202196

203197
Socket.prototype.get = function (opt) {
@@ -214,7 +208,6 @@ Socket.prototype.getsockopt = Socket.prototype.get;
214208
* @param {String} addr
215209
* @param {Function} cb
216210
* @return {Socket} for chaining
217-
* @api public
218211
*/
219212

220213
Socket.prototype.bind = function (addr, cb) {
@@ -238,7 +231,6 @@ Socket.prototype.bind = function (addr, cb) {
238231
*
239232
* @param {String} addr
240233
* @return {Socket} for chaining
241-
* @api public
242234
*/
243235

244236
Socket.prototype.bindSync = function (addr) {
@@ -254,7 +246,6 @@ Socket.prototype.bindSync = function (addr) {
254246
* @param {String} addr
255247
* @param {Function} cb
256248
* @return {Socket} for chaining
257-
* @api public
258249
*/
259250

260251
Socket.prototype.unbind = function (addr, cb) {
@@ -282,7 +273,6 @@ Socket.prototype.unbind = function (addr, cb) {
282273
*
283274
* @param {String} addr
284275
* @return {Socket} for chaining
285-
* @api public
286276
*/
287277

288278
Socket.prototype.unbindSync = function (addr) {
@@ -310,7 +300,6 @@ Socket.prototype.connect = function (addr) {
310300
*
311301
* @param {String} addr
312302
* @return {Socket} for chaining
313-
* @api public
314303
*/
315304

316305
Socket.prototype.disconnect = function (addr) {
@@ -326,7 +315,6 @@ Socket.prototype.disconnect = function (addr) {
326315
* @param {Number} timer interval in ms > 0 or Undefined for default
327316
* @param {Number} The maximum number of events to read on each interval, default is 1, use 0 for reading all events
328317
* @return {Socket} for chaining
329-
* @api public
330318
*/
331319

332320
Socket.prototype.monitor = function (interval, numOfEvents) {
@@ -353,7 +341,6 @@ Socket.prototype.monitor = function (interval, numOfEvents) {
353341
* and close the socket
354342
*
355343
* @return {Socket} for chaining
356-
* @api public
357344
*/
358345

359346
Socket.prototype.unmonitor = function () {
@@ -369,7 +356,6 @@ Socket.prototype.unmonitor = function () {
369356
*
370357
* @param {String} filter
371358
* @return {Socket} for chaining
372-
* @api public
373359
*/
374360

375361
Socket.prototype.subscribe = function (filter) {
@@ -382,7 +368,6 @@ Socket.prototype.subscribe = function (filter) {
382368
*
383369
* @param {String} filter
384370
* @return {Socket} for chaining
385-
* @api public
386371
*/
387372

388373
Socket.prototype.unsubscribe = function (filter) {
@@ -397,7 +382,6 @@ Socket.prototype.unsubscribe = function (filter) {
397382
* @param {Number} [flags]
398383
* @param {Function} [cb]
399384
* @return {Socket} for chaining
400-
* @api public
401385
*/
402386

403387
Socket.prototype.send = function (msg, flags, cb) {
@@ -516,7 +500,6 @@ Socket.prototype._flushWrites = function () {
516500
* Close the socket.
517501
*
518502
* @return {Socket} for chaining
519-
* @api public
520503
*/
521504

522505
Socket.prototype.close = function () {
@@ -530,7 +513,6 @@ Socket.prototype.close = function () {
530513
* @param {String} type
531514
* @param {Object} options
532515
* @return {Socket}
533-
* @api public
534516
*/
535517

536518
exports.createSocket = function (type, options, ctx) {
@@ -552,3 +534,4 @@ exports.createSocket = function (type, options, ctx) {
552534

553535
exports.Socket = Socket;
554536
exports.types = types;
537+
exports.opts = opts;

test/context.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
var zmq = require('..')
2-
, should = require('should')
3-
, semver = require('semver')
1+
var zmq = require('..');
2+
var should = require('should');
3+
var semver = require('semver');
44

5-
describe('context', function() {
5+
describe('context', function () {
66
if (!semver.gte(zmq.version, '3.2.0')) {
77
return console.warn('Test requires libzmq >= 3.2.0');
88
}
99

10-
it('should support setting max io threads', function(done) {
10+
it('should support setting max io threads', function (done) {
1111
var ctx = zmq.getDefaultContext();
1212

1313
ctx.set('ZMQ_IO_THREADS', 3);
@@ -16,7 +16,7 @@ describe('context', function() {
1616
done();
1717
});
1818

19-
it('should support setting max number of sockets', function(done) {
19+
it('should support setting max number of sockets', function (done) {
2020
var ctx = zmq.getDefaultContext();
2121

2222
var currMaxSockets = ctx.get('ZMQ_MAX_SOCKETS');

test/exports.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ var zmq = require('..')
33
, should = require('should')
44
, semver = require('semver');
55

6-
describe('exports', function(){
7-
it('should export a valid version', function(){
6+
describe('exports', function () {
7+
it('should export a valid version', function () {
88
semver.valid(zmq.version).should.be.ok;
99
});
1010

11-
it('should generate valid curve keypair', function(done) {
11+
it('should generate valid curve keypair', function (done) {
1212
try {
1313
var rep = zmq.socket('rep');
1414
rep.set('curve_server', 0);
@@ -27,7 +27,7 @@ describe('exports', function(){
2727
done();
2828
});
2929

30-
it('should export methods', function(){
30+
it('should export methods', function () {
3131
zmq.socket.should.be.a.Function;
3232
zmq.createSocket.should.be.a.Function;
3333
zmq.context.should.be.a.Function;

test/gc.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
var zmq = require('..');
2+
var should = require('should');
13

2-
var zmq = require('..')
3-
, should = require('should');
4-
5-
it('should cooperate with gc', function(done){
4+
it('should cooperate with gc', function (done) {
65
var a = zmq.socket('dealer');
76
var b = zmq.socket('dealer');
87

test/socket.error-callback.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11

2-
var zmq = require('..')
3-
, should = require('should')
4-
, semver = require('semver');
2+
var zmq = require('..');
3+
var should = require('should');
4+
var semver = require('semver');
55

6-
var version = semver.gte(zmq.version, '3.2.0');
7-
8-
describe('socket.error-callback', function(){
9-
var sock;
10-
11-
if (!version) {
6+
describe('socket.error-callback', function () {
7+
if (!semver.gte(zmq.version, '3.2.0')) {
128
return console.warn("ZMQ_ROUTER_MANDATORY requires libzmq 3.2.0, skipping test");
139
}
1410

11+
var sock;
12+
1513
it('should create a socket and set ZMQ_ROUTER_MANDATORY', function () {
1614
sock = zmq.socket('router');
1715
sock.set('ZMQ_ROUTER_MANDATORY', 1);

test/socket.events.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
var zmq = require('..')
22
, should = require('should');
33

4-
describe('socket.events', function(){
4+
describe('socket.events', function () {
55

6-
it('should support events', function(done){
7-
var rep = zmq.socket('rep')
8-
, req = zmq.socket('req');
6+
it('should support events', function (done) {
7+
var rep = zmq.socket('rep');
8+
var req = zmq.socket('req');
99

10-
rep.on('message', function(msg){
10+
rep.on('message', function (msg) {
1111
msg.should.be.an.instanceof(Buffer);
1212
msg.toString().should.equal('hello');
1313
rep.send('world');
@@ -17,9 +17,9 @@ describe('socket.events', function(){
1717
if (error) throw error;
1818
});
1919

20-
rep.on('bind', function(){
20+
rep.on('bind', function () {
2121
req.connect('inproc://stuffevents');
22-
req.on('message', function(msg){
22+
req.on('message', function (msg) {
2323
msg.should.be.an.instanceof(Buffer);
2424
msg.toString().should.equal('world');
2525
req.close();

0 commit comments

Comments
 (0)