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

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

PR-URL: #123
Fixes: #120
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
richardlau committed Mar 5, 2019
1 parent ae484a1 commit d28201c
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,37 @@ 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];
const int family = addr->sa_family;
const void* src = family == AF_INET ?
static_cast<void*>(
&(reinterpret_cast<sockaddr_in*>(addr)->sin_addr)) :
static_cast<void*>(
&(reinterpret_cast<sockaddr_in6*>(addr)->sin6_addr));
if (uv_inet_ntop(family, src, host, sizeof(host)) == 0) {
const int port = 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 +328,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 d28201c

Please sign in to comment.