diff --git a/docs/server.md b/docs/server.md index 711003d..efaa25a 100644 --- a/docs/server.md +++ b/docs/server.md @@ -39,9 +39,10 @@ Known compatible loggers are: Set this property to reject connections when the server's connection count gets high. -### connections (getter only) +### connections (getter only) - DEPRECATED -The number of concurrent connections on the server. +The number of concurrent connections on the server. This property is deprecated, +please use server.getConnections() instead. ### url @@ -96,6 +97,13 @@ This file descriptor must have already had the `bind(2)` and `listen(2)` system calls invoked on it. Additionally, it must be set non-blocking; try `fcntl(fd, F_SETFL, O_NONBLOCK)`. +## Inspecting server state + +### server.getConnections(callback) + +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 +should take two arguments err and count. + # Routes The LDAP server API is meant to be the LDAP-equivalent of the express/restify diff --git a/lib/server.js b/lib/server.js index fbc8dc0..38799b1 100644 --- a/lib/server.js +++ b/lib/server.js @@ -697,6 +697,10 @@ Server.prototype.address = function () { return this.server.address() } +Server.prototype.getConnections = function (callback) { + return this.server.getConnections(callback) +} + Server.prototype._getRoute = function (_dn, backend) { assert.ok(dn) diff --git a/test/server.test.js b/test/server.test.js index 22bd828..5ec2528 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -21,6 +21,30 @@ tap.test('basic create', function (t) { t.end() }) +tap.test('connection count', function (t) { + const server = ldap.createServer() + t.ok(server) + server.listen(0, 'localhost', function () { + t.ok(true, 'server listening on ' + server.url) + + server.getConnections(function (err, count) { + t.error(err) + t.equal(count, 0) + + const client = ldap.createClient({ url: server.url }) + client.on('connect', function () { + t.ok(true, 'client connected') + server.getConnections(function (err, count) { + t.error(err) + t.equal(count, 1) + client.unbind() + server.close(() => t.end()) + }) + }) + }) + }) +}) + tap.test('properties', function (t) { const server = ldap.createServer() t.equal(server.name, 'LDAPServer')