Skip to content

Commit

Permalink
doc: add tls server.close() callback docs
Browse files Browse the repository at this point in the history
Also, tests to confirm its existence.
  • Loading branch information
sam-github committed Dec 30, 2014
1 parent c07fac0 commit 61ac711
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions doc/api/tls.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,11 @@ when the server has been bound.
See `net.Server` for more information.


### server.close()
### server.close([callback])

Stops the server from accepting new connections. This function is
asynchronous, the server is finally closed when the server emits a `'close'`
event.
event. Optionally, you can pass a callback to listen for the `'close'` event.

### server.address()

Expand Down
11 changes: 10 additions & 1 deletion test/parallel/test-tls-connect-simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var fs = require('fs');

var clientConnected = 0;
var serverConnected = 0;
var serverCloseCallbacks = 0;
var serverCloseEvents = 0;

var options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
Expand All @@ -34,7 +36,12 @@ var options = {

var server = tls.Server(options, function(socket) {
if (++serverConnected === 2) {
server.close();
server.close(function() {
++serverCloseCallbacks;
});
server.on('close', function() {
++serverCloseEvents;
});
}
});

Expand All @@ -60,4 +67,6 @@ server.listen(common.PORT, function() {
process.on('exit', function() {
assert.equal(clientConnected, 2);
assert.equal(serverConnected, 2);
assert.equal(serverCloseCallbacks, 1);
assert.equal(serverCloseEvents, 1);
});

0 comments on commit 61ac711

Please sign in to comment.