Skip to content

Commit

Permalink
Fix CI failures on ubuntu1804
Browse files Browse the repository at this point in the history
Ports fixes from core:
nodejs/node#25962
nodejs/node#26140

Fixes: nodejs#120
  • Loading branch information
richardlau committed Feb 21, 2019
1 parent c1cec13 commit 78d03d3
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,32 @@ void SetCommandLine() {
#endif
}

/*******************************************************************************
* Utility function to format socket information.
*******************************************************************************/
void reportEndpoint(uv_handle_t* h, struct sockaddr* addr, const char* prefix,
std::ostringstream& out) {
uv_getnameinfo_t endpoint;
if (uv_getnameinfo(h->loop, &endpoint, nullptr, addr, NI_NUMERICSERV) == 0) {
out << prefix << endpoint.host << ":" << endpoint.service;
} else {
char host[INET6_ADDRSTRLEN];
int family = addr->sa_family;
if (uv_inet_ntop(family, addr, host, sizeof(host)) == 0) {
std::string port = std::to_string(ntohs(family == AF_INET ?
reinterpret_cast<sockaddr_in*>(addr)->sin_port :
reinterpret_cast<sockaddr_in6*>(addr)->sin6_port));
out << prefix << host << ":" << port;
}
}
}

/*******************************************************************************
* Utility function to format libuv socket information.
*******************************************************************************/
void reportEndpoints(uv_handle_t* h, std::ostringstream& out) {
struct sockaddr_storage addr_storage;
struct sockaddr* addr = (sockaddr*)&addr_storage;
char hostbuf[NI_MAXHOST];
char portbuf[NI_MAXSERV];
uv_any_handle* handle = (uv_any_handle*)h;
int addr_size = sizeof(addr_storage);
int rc = -1;
Expand All @@ -305,23 +323,13 @@ void reportEndpoints(uv_handle_t* h, std::ostringstream& out) {
default: break;
}
if (rc == 0) {
// getnameinfo will format host and port and handle IPv4/IPv6.
rc = getnameinfo(addr, addr_size, hostbuf, sizeof(hostbuf), portbuf,
sizeof(portbuf), NI_NUMERICSERV);
if (rc == 0) {
out << std::string(hostbuf) << ":" << std::string(portbuf);
}
reportEndpoint(h, addr, "", out);

if (h->type == UV_TCP) {
// Get the remote end of the connection.
rc = uv_tcp_getpeername(&(handle->tcp), addr, &addr_size);
if (rc == 0) {
rc = getnameinfo(addr, addr_size, hostbuf, sizeof(hostbuf), portbuf,
sizeof(portbuf), NI_NUMERICSERV);
if (rc == 0) {
out << " connected to ";
out << std::string(hostbuf) << ":" << std::string(portbuf);
}
reportEndpoint(h, addr, " connected to ", out);
} else if (rc == UV_ENOTCONN) {
out << " (not connected)";
}
Expand Down

0 comments on commit 78d03d3

Please sign in to comment.