-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: honor default values in Socket constructor
Specifically `readable` and `writable` that default to `false`. PR-URL: #19971 Fixes: libuv/libuv#1794 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
- Loading branch information
1 parent
a4cba2d
commit a342cd6
Showing
4 changed files
with
55 additions
and
8 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,43 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
function test(sock, readable, writable) { | ||
let socket; | ||
if (sock instanceof net.Socket) { | ||
socket = sock; | ||
} else { | ||
socket = new net.Socket(sock); | ||
socket.unref(); | ||
} | ||
|
||
assert.strictEqual(socket.readable, readable); | ||
assert.strictEqual(socket.writable, writable); | ||
} | ||
|
||
test(undefined, false, false); | ||
|
||
const server = net.createServer(common.mustCall((socket) => { | ||
test(socket, true, true); | ||
test({ handle: socket._handle }, false, false); | ||
test({ handle: socket._handle, readable: true, writable: true }, true, true); | ||
if (socket._handle.fd >= 0) { | ||
test(socket._handle.fd, false, false); | ||
test({ fd: socket._handle.fd }, false, false); | ||
test({ fd: socket._handle.fd, readable: true, writable: true }, true, true); | ||
} | ||
|
||
server.close(); | ||
})); | ||
|
||
server.listen(common.mustCall(() => { | ||
const { port } = server.address(); | ||
const socket = net.connect(port, common.mustCall(() => { | ||
test(socket, true, true); | ||
socket.end(); | ||
})); | ||
|
||
test(socket, false, true); | ||
})); |