diff --git a/lib/agent.js b/lib/agent.js index 3074bb3..21c19e9 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -40,6 +40,31 @@ AgentMIBDecor.prototype.instancePossible = function () { return (this._scalar || this._column); }; +function +Agent(options) +{ + var self = this; + + Listener.call(this, options); + + if (typeof (options.dtrace) !== 'object') + throw new TypeError('options.dtrace (object) is required'); + + this._dtrace = options.dtrace; + + Object.keys(AGENT_PROBES).forEach(function (p) { + var args = AGENT_PROBES[p].splice(0); + args.unshift(p); + + self._dtrace.addProbe.apply(self._dtrace, args); + }); + + this._dtrace.enable(); + + this._mib = new MIB(); +} +util.inherits(Agent, Listener); + Agent.prototype._add_provider = function _add_provider(prov) { var self = this; var decor; @@ -84,31 +109,6 @@ Agent.prototype.addProviders = function addProviders(prov) { } }; -function -Agent(options) -{ - var self = this; - - Listener.call(this, options); - - if (typeof (options.dtrace) !== 'object') - throw new TypeError('options.dtrace (object) is required'); - - this._dtrace = options.dtrace; - - Object.keys(AGENT_PROBES).forEach(function (p) { - var args = AGENT_PROBES[p].splice(0); - args.unshift(p); - - self._dtrace.addProbe.apply(self._dtrace, args); - }); - - this._dtrace.enable(); - - this._mib = new MIB(); -} -util.inherits(Agent, Listener); - /* * The provider is expected to provide one of three things for each iteration * requested of it: diff --git a/lib/listener.js b/lib/listener.js index 93c1cf6..17d7098 100644 --- a/lib/listener.js +++ b/lib/listener.js @@ -42,6 +42,13 @@ Listener.prototype.bind = function bind(arg, cb) { cb(); }); + conn.on('error', function (err) { + if (cb) + cb(err || new Error('Unknown binding error')); + else + throw err; + }); + conn.bind(arg.port, arg.addr); }; diff --git a/lib/protocol/message.js b/lib/protocol/message.js index 4d31f28..4de913f 100644 --- a/lib/protocol/message.js +++ b/lib/protocol/message.js @@ -138,41 +138,36 @@ SnmpMessage.prototype.encode = function encode() function ParseContext() { - this.ASN1 = ASN1; - this.pdu = PDU; - this.varbind = varbind; - this.data = data; - this.message = module.exports; - this.content = undefined; -} + var self = { + ASN1: ASN1, + pdu: PDU, + varbind: varbind, + data: data, + message: module.exports, + content: undefined, + }; + + self.setContent = function (content) { + self.content = content; + }; + + self.parseError = function (str, hash) { + throw new MessageParseError(str, hash); + }; + + self.parse = function (raw, src) { + parser.yy = this; -ParseContext.prototype.parse = function parse(raw, src) -{ - /* - * This is vile. Unfortunately, the parser generated by Jison isn't an - * object instance, nor is it anything that can construct one. This - * doesn't really matter because we don't do anything asynchronous - * during parsing, but it's still wrong. - */ - parser.yy = this; - - parser.parse(raw.buf); - if (!this.content) - throw new EmptyMessageError(); - - this.content._setOrigin(raw, src); - return (this.content); -}; + parser.parse(raw.buf); + if (!self.content) + throw new EmptyMessageError(); -ParseContext.prototype.parseError = function parseError(str, hash) -{ - throw new MessageParseError(str, hash); -}; - -ParseContext.prototype.setContent = function setContent(content) -{ - this.content = content; -}; + self.content._setOrigin(raw, src); + return self.content; + }; + + return self; +} function parseMessage(arg) diff --git a/package.json b/package.json index f9f49fc..610b164 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,10 @@ "node": ">=0.6.9" }, "dependencies": { - "jison": "0.3", - "asn1": "~0.2.2", - "bunyan": "~0.21", - "dtrace-provider": "~0.4" + "jison": "~0.4", + "asn1": "~0.2", + "bunyan": "~1.7", + "dtrace-provider": "~0.6" }, "devDependencies": { "tap": "~0.4"