-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: add new options to
net.Socket
and net.Server
- Loading branch information
1 parent
e4aa575
commit 7c9b51e
Showing
6 changed files
with
192 additions
and
6 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
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,56 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
const truthyValues = [true, 1, 'true', {}, []]; | ||
const delays = [[123, 0], [456123, 456], [-123000, 0], [undefined, 0]]; | ||
const falseyValues = [false, 0, '']; | ||
|
||
const genSetKeepAlive = (desiredEnable, desiredDelay) => (enable, delay) => { | ||
assert.strictEqual(enable, desiredEnable); | ||
assert.strictEqual(delay, desiredDelay); | ||
}; | ||
|
||
for (const value of truthyValues) { | ||
for (const delay of delays) { | ||
const server = net.createServer(); | ||
|
||
server.listen(0, common.mustCall(function() { | ||
const port = server.address().port; | ||
|
||
const client = net.connect( | ||
{ port, keepAlive: value, keepAliveInitialDelay: delay[0] }, | ||
common.mustCall(() => client.end()) | ||
); | ||
|
||
client._handle.setKeepAlive = common.mustCall( | ||
genSetKeepAlive(true, delay[1]) | ||
); | ||
|
||
client.on('end', common.mustCall(function() { | ||
server.close(); | ||
})); | ||
})); | ||
} | ||
} | ||
|
||
for (const value of falseyValues) { | ||
const server = net.createServer(); | ||
|
||
server.listen(0, common.mustCall(function() { | ||
const port = server.address().port; | ||
|
||
const client = net.connect( | ||
{ port, keepAlive: value }, | ||
common.mustCall(() => client.end()) | ||
); | ||
|
||
client._handle.setKeepAlive = common.mustNotCall(); | ||
|
||
client.on('end', common.mustCall(function() { | ||
server.close(); | ||
})); | ||
})); | ||
} |
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,49 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
const truthyValues = [true, 1, 'true', {}, []]; | ||
const falseyValues = [false, 0, '']; | ||
const genSetNoDelay = (desiredArg) => (enable) => { | ||
assert.strictEqual(enable, desiredArg); | ||
}; | ||
|
||
for (const value of truthyValues) { | ||
const server = net.createServer(); | ||
|
||
server.listen(0, common.mustCall(function() { | ||
const port = server.address().port; | ||
|
||
const client = net.connect( | ||
{ port, noDelay: value }, | ||
common.mustCall(() => client.end()) | ||
); | ||
|
||
client._handle.setNoDelay = common.mustCall(genSetNoDelay(true)); | ||
|
||
client.on('end', common.mustCall(function() { | ||
server.close(); | ||
})); | ||
})); | ||
} | ||
|
||
for (const value of falseyValues) { | ||
const server = net.createServer(); | ||
|
||
server.listen(0, common.mustCall(function() { | ||
const port = server.address().port; | ||
|
||
const client = net.connect( | ||
{ port, noDelay: value }, | ||
common.mustCall(() => client.end()) | ||
); | ||
|
||
client._handle.setNoDelay = common.mustNotCall(); | ||
|
||
client.on('end', common.mustCall(function() { | ||
server.close(); | ||
})); | ||
})); | ||
} |