Skip to content

Commit

Permalink
#11 TrapListener falls afoul of Node 0.10 bind semantics
Browse files Browse the repository at this point in the history
#12 Bunyan dependency change and logging fix
  • Loading branch information
Keith M Wesolowski committed May 21, 2013
1 parent d2c2148 commit a9afa1e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
14 changes: 11 additions & 3 deletions lib/trap_listener.js
Expand Up @@ -73,7 +73,7 @@ TrapListener.prototype._recv = function _recv(raw, src) {
this._process_msg(msg);
};

TrapListener.prototype.bind = function bind(arg) {
TrapListener.prototype.bind = function bind(arg, cb) {
var self = this;
var conn;

Expand All @@ -87,6 +87,9 @@ TrapListener.prototype.bind = function bind(arg) {
typeof (arg.addr) !== 'string')
throw new TypeError('arg.addr must be a string');

if (cb !== undefined && typeof (cb) !== 'function')
throw new TypeError('cb must be a function');

conn = dgram.createSocket(arg.family);
conn.on('message', function _recv_binder(msg, rinfo) {
var raw = {
Expand All @@ -102,9 +105,14 @@ TrapListener.prototype.bind = function bind(arg) {
});
this._connections.push(conn);

conn.on('listening', function () {
self._log.info('Bound to ' + conn.address().address + ':' +
conn.address().port);
if (cb)
cb();
});

conn.bind(arg.port, arg.addr);
this._log.info('Bound to ' + conn.address().address + ':' +
conn.address().port);
};

TrapListener.prototype.close = function close() {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -2,7 +2,7 @@
"author": "Keith M Wesolowski <keith.wesolowski@joyent.com>",
"name": "snmpjs",
"description": "Simple Network Management Protocol toolkit",
"version": "0.1.3",
"version": "0.1.4",
"repository": {
"type": "git",
"url": "git://github.com/wesolows/node-snmpjs.git"
Expand All @@ -17,7 +17,7 @@
"dependencies": {
"jison": "0.3",
"asn1": "~0.1",
"bunyan": "~0.18",
"bunyan": "~0.21",
"dtrace-provider": "~0.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion tl.js
Expand Up @@ -26,7 +26,7 @@ tl = snmp.createTrapListener({
log: log
});

tl.bind({ family: 'udp4', port: 162 });
tl.on('trap', function (msg) {
console.log(util.inspect(snmp.message.serializer(msg), false, null));
});
tl.bind({ family: 'udp4', port: 162 });

0 comments on commit a9afa1e

Please sign in to comment.