Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Deduplicate UV_FS_EVENT and UV_FS_POLL handling
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlau committed Mar 9, 2017
1 parent 8f93cde commit 4815c8a
Showing 1 changed file with 23 additions and 38 deletions.
61 changes: 23 additions & 38 deletions src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -494,50 +494,35 @@ static void walkHandle(uv_handle_t* h, void* arg) {
std::ostream* out = reinterpret_cast<std::ostream*>(arg);
uv_any_handle* handle = (uv_any_handle*)h;

#define UV_FS_CASE(t, uv_function) \
do { \
char *buffer = nullptr; \
int rc; \
size_t size = 0; \
type = #t; \
/* First call to get required buffer size. */ \
rc = uv_function(&(handle->t), buffer, &size); \
if (rc == UV_ENOBUFS) { \
buffer = (char *)malloc(size); \
rc = uv_function(&(handle->t), buffer, &size); \
if (rc == 0) { \
/* buffer is not null terminated. */ \
std::string name(buffer, size); \
data << "filename: " << name; \
} \
free(buffer); \
} \
} \
while (0)

// List all the types so we get a compile warning if we've missed one,
// (using default: supresses the compiler warning.)
switch (h->type) {
case UV_UNKNOWN_HANDLE: type = "unknown"; break;
case UV_ASYNC: type = "async"; break;
case UV_CHECK: type = "check"; break;
case UV_FS_EVENT: {
char *buffer = nullptr;
int rc;
size_t size = 0;
type = "fs_event";
// First call to get required buffer size.
rc = uv_fs_event_getpath(&(handle->fs_event), buffer, &size);
if (rc == UV_ENOBUFS) {
buffer = (char *)malloc(size);
rc = uv_fs_event_getpath(&(handle->fs_event), buffer, &size);
if (rc == 0) {
// buffer is not null terminated.
std::string name(buffer, size);
data << "filename: " << name;
}
free(buffer);
}
break;
}
case UV_FS_POLL: {
char *buffer = nullptr;
int rc;
size_t size = 0;
type = "fs_poll";
// First call to get required buffer size.
rc = uv_fs_poll_getpath(&(handle->fs_poll), buffer, &size);
if (rc == UV_ENOBUFS) {
buffer = (char *)malloc(size);
rc = uv_fs_poll_getpath(&(handle->fs_poll), buffer, &size);
if (rc == 0) {
// buffer is not null terminated.
std::string name(buffer, size);
data << "filename: " << name;
}
free(buffer);
}
break;
}
case UV_FS_EVENT: UV_FS_CASE(fs_event, uv_fs_event_getpath); break;
case UV_FS_POLL: UV_FS_CASE(fs_poll, uv_fs_poll_getpath); break;
case UV_HANDLE: type = "handle"; break;
case UV_IDLE: type = "idle"; break;
case UV_NAMED_PIPE: type = "pipe"; break;
Expand Down

0 comments on commit 4815c8a

Please sign in to comment.