Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit a67303e

Browse files
authored
Merge pull request #598 from jonekdahl/issue-415
Add server.getConnections (fix #415)
2 parents 8384a47 + 7c00ca8 commit a67303e

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

docs/server.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ Known compatible loggers are:
3939
Set this property to reject connections when the server's connection count gets
4040
high.
4141

42-
### connections (getter only)
42+
### connections (getter only) - DEPRECATED
4343

44-
The number of concurrent connections on the server.
44+
The number of concurrent connections on the server. This property is deprecated,
45+
please use server.getConnections() instead.
4546

4647
### url
4748

@@ -96,6 +97,13 @@ This file descriptor must have already had the `bind(2)` and `listen(2)` system
9697
calls invoked on it. Additionally, it must be set non-blocking; try
9798
`fcntl(fd, F_SETFL, O_NONBLOCK)`.
9899

100+
## Inspecting server state
101+
102+
### server.getConnections(callback)
103+
104+
The LDAP server API mirrors the [Node.js `server.getConnections` API](https://nodejs.org/dist/latest-v12.x/docs/api/net.html#net_server_getconnections_callback). Callback
105+
should take two arguments err and count.
106+
99107
# Routes
100108

101109
The LDAP server API is meant to be the LDAP-equivalent of the express/restify

lib/server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,10 @@ Server.prototype.address = function () {
697697
return this.server.address()
698698
}
699699

700+
Server.prototype.getConnections = function (callback) {
701+
return this.server.getConnections(callback)
702+
}
703+
700704
Server.prototype._getRoute = function (_dn, backend) {
701705
assert.ok(dn)
702706

test/server.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@ tap.test('basic create', function (t) {
2121
t.end()
2222
})
2323

24+
tap.test('connection count', function (t) {
25+
const server = ldap.createServer()
26+
t.ok(server)
27+
server.listen(0, 'localhost', function () {
28+
t.ok(true, 'server listening on ' + server.url)
29+
30+
server.getConnections(function (err, count) {
31+
t.error(err)
32+
t.equal(count, 0)
33+
34+
const client = ldap.createClient({ url: server.url })
35+
client.on('connect', function () {
36+
t.ok(true, 'client connected')
37+
server.getConnections(function (err, count) {
38+
t.error(err)
39+
t.equal(count, 1)
40+
client.unbind()
41+
server.close(() => t.end())
42+
})
43+
})
44+
})
45+
})
46+
})
47+
2448
tap.test('properties', function (t) {
2549
const server = ldap.createServer()
2650
t.equal(server.name, 'LDAPServer')

0 commit comments

Comments
 (0)