Merge pull request #598 from jonekdahl/issue-415
Add server.getConnections (fix #415)
This commit is contained in:
commit
a67303e7a4
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue