Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions lib/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
61 changes: 28 additions & 33 deletions lib/protocol/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down