Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

flatten some logic

  • Loading branch information...
commit f2101ef94b0f662931a126ba6c47bdfdb0f03c44 1 parent f8c4f76
James Halliday authored

Showing 1 changed file with 38 additions and 41 deletions. Show diff stats Hide diff stats

  1. +38 41 index.js
79 index.js
@@ -27,53 +27,50 @@ exports.connect = function () {
27 27 var cb = args.function;
28 28 var options = args.object || {};
29 29
  30 + var port = args.number || 25;
  31 + var host = args.string || 'localhost';
  32 + var tlsOpts = options.tls;
  33 +
30 34 if (args.string && args.string.match(/^[.\/]/)) {
31 35 // unix socket
32 36 stream = net.createConnection(args.string);
33 37 }
34   - else {
35   - port = args.number || 25;
36   - host = args.string || 'localhost';
37   - var tlsOpts = options.tls;
38   -
39   - if (tlsOpts) {
40   - stream = tls.connect(port, host, tlsOpts, function () {
41   - var pending = stream.listeners('secureConnect').length;
42   - var allOk = pending === 0 ? stream.authorized : true;
43   - if (pending === 0) done()
44   - else {
45   - var ack = {
46   - accept : function (ok) {
47   - allOk = allOk && (ok !== false);
48   - if (--pending === 0) done();
49   - },
50   - reject : function () {
51   - allOk = false;
52   - if (--pending === 0) done();
53   - }
54   - };
55   - stream.emit('secureConnect', stream, ack);
56   - }
57   -
58   - function done () {
59   - if (!allOk) {
60   - stream.end();
61   - stream.emit('error', new Error(stream.authorizationError));
  38 + else if (tlsOpts) {
  39 + stream = tls.connect(port, host, tlsOpts, function () {
  40 + var pending = stream.listeners('secureConnect').length;
  41 + var allOk = pending === 0 ? stream.authorized : true;
  42 + if (pending === 0) done()
  43 + else {
  44 + var ack = {
  45 + accept : function (ok) {
  46 + allOk = allOk && (ok !== false);
  47 + if (--pending === 0) done();
  48 + },
  49 + reject : function () {
  50 + allOk = false;
  51 + if (--pending === 0) done();
62 52 }
63   - else cb(proto.server(stream));
  53 + };
  54 + stream.emit('secureConnect', stream, ack);
  55 + }
  56 +
  57 + function done () {
  58 + if (!allOk) {
  59 + stream.end();
  60 + stream.emit('error', new Error(stream.authorizationError));
64 61 }
65   - });
66   -
67   - }
68   - else if (options.stream) {
69   - cb(proto.server(options.stream));
70   - }
71   - else {
72   - stream = net.createConnection(port, host);
73   - stream.on('connect', function () {
74   - cb(proto.server(stream));
75   - });
76   - }
  62 + else cb(proto.server(stream));
  63 + }
  64 + });
  65 + }
  66 + else if (options.stream) {
  67 + cb(proto.server(options.stream));
  68 + }
  69 + else {
  70 + stream = net.createConnection(port, host);
  71 + stream.on('connect', function () {
  72 + cb(proto.server(stream));
  73 + });
77 74 }
78 75
79 76 return stream;

0 comments on commit f2101ef

Please sign in to comment.
Something went wrong with that request. Please try again.