Permalink
Browse files

add some simple debug output

  • Loading branch information...
1 parent 78b18fb commit a8aefea696f55663dd7fecc44bc80c202909a0cd @mscdex committed Mar 11, 2013
Showing with 13 additions and 7 deletions.
  1. +13 −7 lib/nntp.js
View
@@ -9,6 +9,7 @@ var tls = require('tls'),
util = require('util'),
SBMH = require('streamsearch'),
inherits = util.inherits,
+ inspect = util.inspect,
RE_CRLF = /\r\n/g,
RE_LIST_ACTIVE = /^(.+)\s+(\d+)\s+(\d+)\s+(.+)$/,
RE_GROUP_DESC = /^([^\s]+)\s+(.+)$/,
@@ -75,14 +76,14 @@ function NNTP() {
this._stream = undefined;
this._buffer = undefined;
this._bufferEnc = undefined;
+ this._debug = false;
this.options = {
host: undefined,
port: undefined,
secure: undefined,
user: undefined,
password: undefined,
- connTimeout: undefined,
- debug: undefined
+ connTimeout: undefined
};
this.connected = false;
};
@@ -138,9 +139,11 @@ NNTP.prototype.connect = function(options) {
this.options.user = options.user || '';
this.options.password = options.password || '';
this.options.connTimeout = options.connTimeout || 60000; // in ms
- this.options.debug = false;
+ var debug;
if (typeof options.debug === 'function')
- this.options.debug = options.debug;
+ debug = this._debug = options.debug;
+ else
+ debug = this._debug = false;
this.reset();
this._caps = {};
@@ -225,7 +228,7 @@ NNTP.prototype.connect = function(options) {
socket.on('data', function(chunk) {
chunk.p = 0;
var chlen = chunk.length, r = 0;
-
+ debug&&debug('< ' + inspect(chunk.toString('binary')));
while (r < chlen) {
if (typeof code !== 'number') {
code = readCode(chunk, code);
@@ -667,10 +670,13 @@ NNTP.prototype._send = function(cmd, params, cb) {
this._curReq = this._queue.shift();
this._socket.write(this._curReq.cmd);
if (this._curReq.params !== undefined) {
+ this._debug('> ' + this._curReq.cmd + ' ' + this._curReq.params);
this._socket.write(' ');
this._socket.write(''+this._curReq.params);
- }
- this._socket.write(bytesCRLF);
+ } else if (this._debug)
+ this._debug('> ' + this._curReq.cmd);
+
+ this._socket.write(B_CRLF);
}
};

0 comments on commit a8aefea

Please sign in to comment.