Skip to content
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

report: add support for UDP connected sockets #27072

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/node_report_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@ static void ReportEndpoints(uv_handle_t* h, JSONWriter* writer) {
}
ReportEndpoint(h, rc == 0 ? addr : nullptr, "localEndpoint", writer);

if (h->type == UV_TCP) {
// Get the remote end of the connection.
rc = uv_tcp_getpeername(&handle->tcp, addr, &addr_size);
ReportEndpoint(h, rc == 0 ? addr : nullptr, "remoteEndpoint", writer);
switch (h->type) {
case UV_UDP:
rc = uv_udp_getpeername(&handle->udp, addr, &addr_size);
break;
case UV_TCP:
rc = uv_tcp_getpeername(&handle->tcp, addr, &addr_size);
break;
default:
break;
}
ReportEndpoint(h, rc == 0 ? addr : nullptr, "remoteEndpoint", writer);
}

// Utility function to format libuv path information.
Expand Down
23 changes: 19 additions & 4 deletions test/report/test-report-uv-handles.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ if (process.argv[2] === 'child') {
// Datagram socket for udp uv handles.
const dgram = require('dgram');
const udp_socket = dgram.createSocket('udp4');
udp_socket.bind({});
const connected_udp_socket = dgram.createSocket('udp4');
udp_socket.bind({}, common.mustCall(() => {
connected_udp_socket.connect(udp_socket.address().port);
}));

// Simple server/connection to create tcp uv handles.
const server = http.createServer((req, res) => {
Expand All @@ -50,6 +53,7 @@ if (process.argv[2] === 'child') {
server.close(() => {
if (watcher) watcher.close();
fs.unwatchFile(__filename);
connected_udp_socket.close();
udp_socket.close();
process.removeListener('disconnect', exit);
});
Expand Down Expand Up @@ -97,6 +101,7 @@ if (process.argv[2] === 'child') {
const prefix = common.isWindows ? '\\\\?\\' : '';
const expected_filename = `${prefix}${__filename}`;
const found_tcp = [];
const found_udp = [];
// Functions are named to aid debugging when they are not called.
const validators = {
fs_event: common.mustCall(function fs_event_validator(handle) {
Expand Down Expand Up @@ -138,10 +143,17 @@ if (process.argv[2] === 'child') {
assert.strictEqual(handle.repeat, 0);
}),
udp: common.mustCall(function udp_validator(handle) {
assert.strictEqual(handle.localEndpoint.port,
child_data.udp_address.port);
if (handle.remoteEndpoint === null) {
assert.strictEqual(handle.localEndpoint.port,
child_data.udp_address.port);
found_udp.push('unconnected');
} else {
assert.strictEqual(handle.remoteEndpoint.port,
child_data.udp_address.port);
found_udp.push('connected');
}
assert(handle.is_referenced);
}),
}, 2),
};
console.log(report.libuv);
for (const entry of report.libuv) {
Expand All @@ -150,6 +162,9 @@ if (process.argv[2] === 'child') {
for (const socket of ['listening', 'inbound', 'outbound']) {
assert(found_tcp.includes(socket), `${socket} TCP socket was not found`);
}
for (const socket of ['connected', 'unconnected']) {
assert(found_udp.includes(socket), `${socket} UDP socket was not found`);
}

// Common report tests.
helper.validateContent(stdout);
Expand Down