-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
feat(ext/net): Add Conn.setNoDelay and Conn.setKeepAlive #13103
Changes from all commits
14968b1
59f86b3
d1f3d8e
d6c7f41
42f34dc
ade7423
edbea11
8c57963
5e04c43
e80a6bd
00f422a
843890c
2b3dbe6
2ed4fdd
5f7cf60
bc2efe2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,6 +238,78 @@ Deno.test({ permissions: { net: true } }, async function netTcpDialListen() { | |
conn.close(); | ||
}); | ||
|
||
Deno.test({ permissions: { net: true } }, async function netTcpSetNoDelay() { | ||
const listener = Deno.listen({ port: 3500 }); | ||
listener.accept().then( | ||
async (conn) => { | ||
assert(conn.remoteAddr != null); | ||
assert(conn.localAddr.transport === "tcp"); | ||
assertEquals(conn.localAddr.hostname, "127.0.0.1"); | ||
assertEquals(conn.localAddr.port, 3500); | ||
await conn.write(new Uint8Array([1, 2, 3])); | ||
conn.close(); | ||
}, | ||
); | ||
|
||
const conn = await Deno.connect({ hostname: "127.0.0.1", port: 3500 }); | ||
conn.setNoDelay(true); | ||
assert(conn.remoteAddr.transport === "tcp"); | ||
assertEquals(conn.remoteAddr.hostname, "127.0.0.1"); | ||
assertEquals(conn.remoteAddr.port, 3500); | ||
assert(conn.localAddr != null); | ||
const buf = new Uint8Array(1024); | ||
const readResult = await conn.read(buf); | ||
assertEquals(3, readResult); | ||
assertEquals(1, buf[0]); | ||
assertEquals(2, buf[1]); | ||
assertEquals(3, buf[2]); | ||
assert(conn.rid > 0); | ||
|
||
assert(readResult !== null); | ||
|
||
const readResult2 = await conn.read(buf); | ||
assertEquals(readResult2, null); | ||
|
||
listener.close(); | ||
conn.close(); | ||
}); | ||
|
||
Deno.test({ permissions: { net: true } }, async function netTcpSetKeepAlive() { | ||
const listener = Deno.listen({ port: 3500 }); | ||
listener.accept().then( | ||
async (conn) => { | ||
assert(conn.remoteAddr != null); | ||
assert(conn.localAddr.transport === "tcp"); | ||
assertEquals(conn.localAddr.hostname, "127.0.0.1"); | ||
assertEquals(conn.localAddr.port, 3500); | ||
await conn.write(new Uint8Array([1, 2, 3])); | ||
conn.close(); | ||
}, | ||
); | ||
|
||
const conn = await Deno.connect({ hostname: "127.0.0.1", port: 3500 }); | ||
conn.setKeepAlive(true); | ||
assert(conn.remoteAddr.transport === "tcp"); | ||
assertEquals(conn.remoteAddr.hostname, "127.0.0.1"); | ||
assertEquals(conn.remoteAddr.port, 3500); | ||
assert(conn.localAddr != null); | ||
const buf = new Uint8Array(1024); | ||
const readResult = await conn.read(buf); | ||
assertEquals(3, readResult); | ||
assertEquals(1, buf[0]); | ||
assertEquals(2, buf[1]); | ||
assertEquals(3, buf[2]); | ||
assert(conn.rid > 0); | ||
|
||
assert(readResult !== null); | ||
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. Same here, since Apologies if I'm missing anything here (this is also probably just a nitpick anyway, so I'm sorry). |
||
|
||
const readResult2 = await conn.read(buf); | ||
assertEquals(readResult2, null); | ||
|
||
listener.close(); | ||
conn.close(); | ||
}); | ||
|
||
Deno.test( | ||
{ | ||
ignore: Deno.build.os === "windows", | ||
|
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.
Considering that:
readResult
equals3
readResult
is aconst
and assigned a primitiveDo we need this assertion or is it redundant?