Quit.js 861 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var Sequence = require('./Sequence');
  2. var Util = require('util');
  3. var Packets = require('../packets');
  4. module.exports = Quit;
  5. Util.inherits(Quit, Sequence);
  6. function Quit(options, callback) {
  7. if (!callback && typeof options === 'function') {
  8. callback = options;
  9. options = {};
  10. }
  11. Sequence.call(this, options, callback);
  12. this._started = false;
  13. }
  14. Quit.prototype.end = function end(err) {
  15. if (this._ended) {
  16. return;
  17. }
  18. if (!this._started) {
  19. Sequence.prototype.end.call(this, err);
  20. return;
  21. }
  22. if (err && err.code === 'ECONNRESET' && err.syscall === 'read') {
  23. // Ignore read errors after packet sent
  24. Sequence.prototype.end.call(this);
  25. return;
  26. }
  27. Sequence.prototype.end.call(this, err);
  28. };
  29. Quit.prototype.start = function() {
  30. this._started = true;
  31. this.emit('packet', new Packets.ComQuitPacket());
  32. };