Skip to content

Commit f3d0591

Browse files
committed
report: use uv_handle_type_name() to get handle type
PR-URL: #25610 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 03ba344 commit f3d0591

File tree

1 file changed

+7
-58
lines changed

1 file changed

+7
-58
lines changed

src/node_report_utils.cc

+7-58
Original file line numberDiff line numberDiff line change
@@ -105,65 +105,26 @@ void ReportPath(uv_handle_t* h, std::ostringstream& out) {
105105

106106
// Utility function to walk libuv handles.
107107
void WalkHandle(uv_handle_t* h, void* arg) {
108-
std::string type;
108+
const char* type = uv_handle_type_name(h->type);
109109
std::ostringstream data;
110110
JSONWriter* writer = static_cast<JSONWriter*>(arg);
111111
uv_any_handle* handle = reinterpret_cast<uv_any_handle*>(h);
112112

113-
// List all the types so we get a compile warning if we've missed one,
114-
// (using default: supresses the compiler warning).
115113
switch (h->type) {
116-
case UV_UNKNOWN_HANDLE:
117-
type = "unknown";
118-
break;
119-
case UV_ASYNC:
120-
type = "async";
121-
break;
122-
case UV_CHECK:
123-
type = "check";
124-
break;
125-
case UV_FS_EVENT: {
126-
type = "fs_event";
127-
ReportPath(h, data);
128-
break;
129-
}
130-
case UV_FS_POLL: {
131-
type = "fs_poll";
114+
case UV_FS_EVENT:
115+
case UV_FS_POLL:
132116
ReportPath(h, data);
133117
break;
134-
}
135-
case UV_HANDLE:
136-
type = "handle";
137-
break;
138-
case UV_IDLE:
139-
type = "idle";
140-
break;
141-
case UV_NAMED_PIPE:
142-
type = "pipe";
143-
break;
144-
case UV_POLL:
145-
type = "poll";
146-
break;
147-
case UV_PREPARE:
148-
type = "prepare";
149-
break;
150-
case UV_PROCESS: {
151-
type = "process";
118+
case UV_PROCESS:
152119
data << "pid: " << handle->process.pid;
153120
break;
154-
}
155-
case UV_STREAM:
156-
type = "stream";
157-
break;
158-
case UV_TCP: {
159-
type = "tcp";
121+
case UV_TCP:
122+
case UV_UDP:
160123
ReportEndpoints(h, data);
161124
break;
162-
}
163125
case UV_TIMER: {
164126
uint64_t due = handle->timer.timeout;
165127
uint64_t now = uv_now(handle->timer.loop);
166-
type = "timer";
167128
data << "repeat: " << uv_timer_get_repeat(&(handle->timer));
168129
if (due > now) {
169130
data << ", timeout in: " << (due - now) << " ms";
@@ -174,35 +135,23 @@ void WalkHandle(uv_handle_t* h, void* arg) {
174135
}
175136
case UV_TTY: {
176137
int height, width, rc;
177-
type = "tty";
178138
rc = uv_tty_get_winsize(&(handle->tty), &width, &height);
179139
if (rc == 0) {
180140
data << "width: " << width << ", height: " << height;
181141
}
182142
break;
183143
}
184-
case UV_UDP: {
185-
type = "udp";
186-
ReportEndpoints(h, data);
187-
break;
188-
}
189144
case UV_SIGNAL: {
190145
// SIGWINCH is used by libuv so always appears.
191146
// See http://docs.libuv.org/en/v1.x/signal.html
192-
type = "signal";
193147
data << "signum: " << handle->signal.signum
194148
#ifndef _WIN32
195149
<< " (" << node::signo_string(handle->signal.signum) << ")"
196150
#endif
197151
<< "";
198152
break;
199153
}
200-
case UV_FILE:
201-
type = "file";
202-
break;
203-
// We shouldn't see "max" type
204-
case UV_HANDLE_TYPE_MAX:
205-
type = "max";
154+
default:
206155
break;
207156
}
208157

0 commit comments

Comments
 (0)