From c851e76f8ca682cdf672cd3449e9b80efa42bfb4 Mon Sep 17 00:00:00 2001 From: Amol Yadav Date: Mon, 2 Feb 2026 03:23:31 -0800 Subject: [PATCH] net: add `setTOS` and `getTOS` to `Socket` PR-URL: https://github.com/nodejs/node/pull/61503 Fixes: https://github.com/nodejs/node/issues/61489 Reviewed-By: Matteo Collina Reviewed-By: Robert Nagy Reviewed-By: Anna Henningsen --- doc/api/net.md | 43 ++++ lib/net.js | 68 ++++++ src/tcp_wrap.cc | 298 +++++++++++++++++++-------- src/tcp_wrap.h | 2 + test/parallel/test-net-socket-tos.js | 100 +++++++++ 5 files changed, 427 insertions(+), 84 deletions(-) create mode 100644 test/parallel/test-net-socket-tos.js diff --git a/doc/api/net.md b/doc/api/net.md index 56f6e3226f4..406fa84e17d 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -743,6 +743,9 @@ it to interact with the client. + +* Returns: {integer} The current TOS value. + +Returns the current Type of Service (TOS) field for IPv4 packets or Traffic +Class for IPv6 packets for this socket. + +`setTypeOfService()` may be called before the socket is connected; the value +will be cached and applied when the socket establishes a connection. +`getTypeOfService()` will return the currently set value even before connection. + +On some platforms (e.g., Linux), certain TOS/ECN bits may be masked or ignored, +and behavior can differ between IPv4 and IPv6 or dual-stack sockets. Callers +should verify platform-specific semantics. + +### `socket.setTypeOfService(tos)` + + + +* `tos` {integer} The TOS value to set (0-255). +* Returns: {net.Socket} The socket itself. + +Sets the Type of Service (TOS) field for IPv4 packets or Traffic Class for IPv6 +Packets sent from this socket. This can be used to prioritize network traffic. + +`setTypeOfService()` may be called before the socket is connected; the value +will be cached and applied when the socket establishes a connection. +`getTypeOfService()` will return the currently set value even before connection. + +On some platforms (e.g., Linux), certain TOS/ECN bits may be masked or ignored, +and behavior can differ between IPv4 and IPv6 or dual-stack sockets. Callers +should verify platform-specific semantics. + ### `socket.timeout`