-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: add support for finished after .destroy()
Calling `finished(socket, cb)` would previously not invoked the callback if the socket was already detroyed. PR-URL: #36635 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
4 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const net = require('net'); | ||
const { finished } = require('stream'); | ||
|
||
const server = net.createServer(function(con) { | ||
con.on('close', common.mustCall()); | ||
}); | ||
|
||
server.listen(0, common.mustCall(function() { | ||
const con = net.connect({ | ||
port: this.address().port | ||
}) | ||
.on('connect', () => { | ||
finished(con, common.mustCall()); | ||
con.destroy(); | ||
finished(con, common.mustCall()); | ||
con.on('close', common.mustCall(() => { | ||
finished(con, common.mustCall(() => { | ||
server.close(); | ||
})); | ||
})); | ||
}) | ||
.end(); | ||
})); |