Skip to content

Commit e303270

Browse files
committed
report: add support for UDP connected sockets
PR-URL: #27072 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]>
1 parent 181052d commit e303270

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/node_report_utils.cc

+10-4
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,17 @@ static void ReportEndpoints(uv_handle_t* h, JSONWriter* writer) {
6666
}
6767
ReportEndpoint(h, rc == 0 ? addr : nullptr, "localEndpoint", writer);
6868

69-
if (h->type == UV_TCP) {
70-
// Get the remote end of the connection.
71-
rc = uv_tcp_getpeername(&handle->tcp, addr, &addr_size);
72-
ReportEndpoint(h, rc == 0 ? addr : nullptr, "remoteEndpoint", writer);
69+
switch (h->type) {
70+
case UV_UDP:
71+
rc = uv_udp_getpeername(&handle->udp, addr, &addr_size);
72+
break;
73+
case UV_TCP:
74+
rc = uv_tcp_getpeername(&handle->tcp, addr, &addr_size);
75+
break;
76+
default:
77+
break;
7378
}
79+
ReportEndpoint(h, rc == 0 ? addr : nullptr, "remoteEndpoint", writer);
7480
}
7581

7682
// Utility function to format libuv path information.

test/report/test-report-uv-handles.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ if (process.argv[2] === 'child') {
3434
// Datagram socket for udp uv handles.
3535
const dgram = require('dgram');
3636
const udp_socket = dgram.createSocket('udp4');
37-
udp_socket.bind({});
37+
const connected_udp_socket = dgram.createSocket('udp4');
38+
udp_socket.bind({}, common.mustCall(() => {
39+
connected_udp_socket.connect(udp_socket.address().port);
40+
}));
3841

3942
// Simple server/connection to create tcp uv handles.
4043
const server = http.createServer((req, res) => {
@@ -50,6 +53,7 @@ if (process.argv[2] === 'child') {
5053
server.close(() => {
5154
if (watcher) watcher.close();
5255
fs.unwatchFile(__filename);
56+
connected_udp_socket.close();
5357
udp_socket.close();
5458
process.removeListener('disconnect', exit);
5559
});
@@ -97,6 +101,7 @@ if (process.argv[2] === 'child') {
97101
const prefix = common.isWindows ? '\\\\?\\' : '';
98102
const expected_filename = `${prefix}${__filename}`;
99103
const found_tcp = [];
104+
const found_udp = [];
100105
// Functions are named to aid debugging when they are not called.
101106
const validators = {
102107
fs_event: common.mustCall(function fs_event_validator(handle) {
@@ -138,10 +143,17 @@ if (process.argv[2] === 'child') {
138143
assert.strictEqual(handle.repeat, 0);
139144
}),
140145
udp: common.mustCall(function udp_validator(handle) {
141-
assert.strictEqual(handle.localEndpoint.port,
142-
child_data.udp_address.port);
146+
if (handle.remoteEndpoint === null) {
147+
assert.strictEqual(handle.localEndpoint.port,
148+
child_data.udp_address.port);
149+
found_udp.push('unconnected');
150+
} else {
151+
assert.strictEqual(handle.remoteEndpoint.port,
152+
child_data.udp_address.port);
153+
found_udp.push('connected');
154+
}
143155
assert(handle.is_referenced);
144-
}),
156+
}, 2),
145157
};
146158
console.log(report.libuv);
147159
for (const entry of report.libuv) {
@@ -150,6 +162,9 @@ if (process.argv[2] === 'child') {
150162
for (const socket of ['listening', 'inbound', 'outbound']) {
151163
assert(found_tcp.includes(socket), `${socket} TCP socket was not found`);
152164
}
165+
for (const socket of ['connected', 'unconnected']) {
166+
assert(found_udp.includes(socket), `${socket} UDP socket was not found`);
167+
}
153168

154169
// Common report tests.
155170
helper.validateContent(stdout);

0 commit comments

Comments
 (0)