-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: persist net.Socket options before connect #880
Closed
+379
−98
Closed
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e61ee49
Working on v2.0.0
chrisdickinson 6870764
doc: update CONTRIBUTING.md
brendanashworth 7180597
Revert "http: don't bother making a copy of the options"
brendanashworth 6bf85bc
test: add test for 06cfff9 regression
brendanashworth 59a5c98
Merge v1.8.1.
chrisdickinson 2632775
doc: update AUTHORS list
rvagg b16a328
doc: add spaces to child.kill example
enaqx 22aafa5
doc: add Fishrock123 to the TC
Fishrock123 a7d7463
tls_wrap: use localhost if options.host is empty
7384ca8
module: remove '' from Module.globalPaths
chrisyip bb254b5
doc: update branch to master
silverwind 3d3083b
buffer: little improve for Buffer.concat method
JacksonTian 1bef717
net: cleanup connect logic
evanlucas 4abe2fa
net: add lookup option to Socket.prototype.connect
evanlucas 102a993
net: persist net.Socket options before connect
evanlucas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
net: persist net.Socket options before connect
Remembers net.Socket options called before connect and retroactively applies them after the handle has been created. This change makes the following function calls more user-friendly: - setKeepAlive() - setNoDelay() - ref() - unref() Related: nodejs/node-v0.x-archive#7077 and nodejs/node-v0.x-archive#8572
commit 102a993ade492bfd3a4365fd06371110abe78709
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var net = require('net'); | ||
|
||
var serverConnection; | ||
var echoServer = net.createServer(function(connection) { | ||
serverConnection = connection; | ||
connection.setTimeout(0); | ||
assert.notEqual(connection.setKeepAlive, undefined); | ||
connection.on('end', function() { | ||
connection.end(); | ||
}); | ||
}); | ||
echoServer.listen(common.PORT); | ||
|
||
echoServer.on('listening', function() { | ||
var clientConnection = new net.Socket(); | ||
// send a keepalive packet after 1000 ms | ||
// and make sure it persists | ||
clientConnection.setKeepAlive(true, 400); | ||
clientConnection.connect(common.PORT); | ||
clientConnection.setTimeout(0); | ||
|
||
setTimeout(function() { | ||
// make sure both connections are still open | ||
assert.equal(serverConnection.readyState, 'open'); | ||
assert.equal(clientConnection.readyState, 'open'); | ||
serverConnection.end(); | ||
clientConnection.end(); | ||
echoServer.close(); | ||
}, 600); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this test actually tests that TCP keep-alive works... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. most of it was taken directly from |
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,33 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var net = require('net'); | ||
var TCPWrap = process.binding('tcp_wrap').TCP; | ||
|
||
var echoServer = net.createServer(function(connection) { | ||
connection.end(); | ||
}); | ||
echoServer.listen(common.PORT); | ||
|
||
var setTrue = 0; | ||
|
||
var Socket = net.Socket; | ||
var setNoDelay = TCPWrap.prototype.setNoDelay; | ||
|
||
TCPWrap.prototype.setNoDelay = function(enable) { | ||
setNoDelay.call(this, enable); | ||
setTrue++; | ||
}; | ||
|
||
echoServer.on('listening', function() { | ||
var sock1 = new Socket(); | ||
// setNoDelay before the handle is created | ||
// there is probably a better way to test this | ||
|
||
sock1.setNoDelay(); | ||
sock1.connect(common.PORT); | ||
sock1.on('end', process.exit); | ||
}); | ||
|
||
process.on('exit', function() { | ||
assert.ok(setTrue); | ||
}); |
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,39 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var net = require('net'); | ||
var TCPWrap = process.binding('tcp_wrap').TCP; | ||
|
||
var echoServer = net.createServer(function(conn) { | ||
conn.end(); | ||
}); | ||
|
||
var ref = TCPWrap.prototype.ref; | ||
var unref = TCPWrap.prototype.unref; | ||
|
||
var refed = false; | ||
var unrefed = false; | ||
|
||
TCPWrap.prototype.ref = function() { | ||
ref.call(this); | ||
refed = true; | ||
}; | ||
|
||
TCPWrap.prototype.unref = function() { | ||
unref.call(this); | ||
unrefed = true; | ||
}; | ||
|
||
echoServer.listen(common.PORT); | ||
|
||
echoServer.on('listening', function() { | ||
var sock = new net.Socket(); | ||
sock.unref(); | ||
sock.ref(); | ||
sock.connect(common.PORT); | ||
sock.on('end', process.exit); | ||
}); | ||
|
||
process.on('exit', function() { | ||
assert.ok(refed); | ||
assert.ok(unrefed); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need new flags for this:
The use of
Function#bind()
is intentional, it avoids the unconditional closure allocation that would happen if you wrote the uncommon path asthis.once('connect', function() { this.setNoDelay(enable); })
.