Skip to content

Commit 2bba85f

Browse files
committed
WIP
1 parent 793d2bf commit 2bba85f

File tree

6 files changed

+59
-59
lines changed

6 files changed

+59
-59
lines changed

index.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
const Server = require('./lib/server')
2-
const Connection = require('./lib/connection')
1+
const Server = require("./lib/server");
2+
const Connection = require("./lib/connection");
33

4-
exports.Server = Server
5-
exports.Connection = Connection
4+
exports.Server = Server;
65

7-
exports.createServer = function (opts, onconnection) {
8-
if (typeof opts === 'function') return exports.createServer(null, opts)
9-
const server = new Server(opts)
10-
if (onconnection) server.on('connection', onconnection)
11-
return server
12-
}
6+
exports.Connection = Connection;
137

14-
exports.connect = function (port, host, opts) {
15-
if (typeof host !== 'string' && host) return exports.connect(port, null, host)
16-
if (!opts) opts = {}
8+
exports.createServer = function createServer(opts, onconnection) {
9+
if (typeof opts === "function") return exports.createServer(undefined, opts);
1710

18-
var connection = new Connection()
11+
const server = new Server(opts);
1912

20-
if (opts.allowHalfOpen) connection.allowHalfOpen = true
21-
connection._connect(port, host || '127.0.0.1')
13+
if (onconnection) server.on("connection", onconnection);
2214

23-
return connection
24-
}
15+
return server;
16+
};
17+
18+
exports.connect = function connect(port, host, opts) {
19+
if (typeof host !== "string" && host)
20+
return exports.connect(port, null, host);
21+
22+
if (!opts) opts = {};
23+
24+
var connection = new Connection();
25+
26+
if (opts.allowHalfOpen) connection.allowHalfOpen = true;
27+
28+
connection._connect(port, host || "127.0.0.1");
29+
30+
return connection;
31+
};

lib/Request.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Request {
2+
constructor(handle) {
3+
this.callback = null;
4+
this.buffer = null;
5+
this.buffers = null;
6+
this.length = 0;
7+
this.lengths = null;
8+
this.handle = handle ? Buffer.alloc(handle) : null;
9+
}
10+
11+
donev(err) {
12+
const cb = this.callback;
13+
const buffers = this.buffers;
14+
const lengths = this.lengths;
15+
16+
this.callback = this.buffers = this.lengths = null;
17+
cb(err, buffers, lengths);
18+
}
19+
20+
done(err, len) {
21+
const cb = this.callback;
22+
const buf = this.buffer;
23+
24+
this.callback = this.buffer = null;
25+
cb(err, buf, len);
26+
}
27+
}
28+
29+
module.exports = Request;

lib/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const binding = require("./binding");
22
const events = require("events");
33
const unordered = require("unordered-set");
44
const RequestQueue = require("./queue");
5-
const lookup = require("./lookup");
5+
const { lookup } = require("dns");
66

77
const EMPTY = Buffer.alloc(0);
88

lib/lookup.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/queue.js

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const Request = require("./Request");
2+
13
class RequestQueue {
24
constructor(size, handle) {
35
this.size = size;
@@ -47,32 +49,4 @@ class RequestQueue {
4749
}
4850
}
4951

50-
class Request {
51-
constructor(handle) {
52-
this.callback = null;
53-
this.buffer = null;
54-
this.buffers = null;
55-
this.length = 0;
56-
this.lengths = null;
57-
this.handle = handle ? Buffer.alloc(handle) : null;
58-
}
59-
60-
donev(err) {
61-
const cb = this.callback;
62-
const buffers = this.buffers;
63-
const lengths = this.lengths;
64-
65-
this.callback = this.buffers = this.lengths = null;
66-
cb(err, buffers, lengths);
67-
}
68-
69-
done(err, len) {
70-
const cb = this.callback;
71-
const buf = this.buffer;
72-
73-
this.callback = this.buffer = null;
74-
cb(err, buf, len);
75-
}
76-
}
77-
7852
module.exports = RequestQueue;

lib/server.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
const binding = require("./binding");
22
const Connection = require("./connection");
3-
const lookup = require("./lookup");
3+
const { lookup } = require("dns");
44
const events = require("events");
55
const semver = require("semver");
66
const os = require("os");
77

88
class Server extends events.EventEmitter {
9-
constructor(opts) {
10-
if (!opts) opts = {};
9+
constructor(opts = {}) {
1110
super();
1211

1312
this.connections = [];

0 commit comments

Comments
 (0)