summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Roland Levillain <rpl@google.com> 2016-01-21 14:01:10 +0000
committer Roland Levillain <rpl@google.com> 2016-01-21 14:01:10 +0000
commit15f9b27adf1e1eb64a42d872f88e95ba637ce775 (patch)
treec0f174d67ce4c447194a5a057b30b32aae3d49d7
parent8ae596fb0496d93b8d9bb5d5b162d7e6c32c39a2 (diff)
Improves recent changes to art::JDWP::JdwpSocketState::Establish.
(This is a follow-up CL to https://android-review.googlesource.com/#/c/197630.) Capture the size of the work buffer passed to gethostbyname_r in a constant and document it. Also wrap long lines in runtime/jdwp/jdwp_socket.cc. Change-Id: Ieb0694c56611a491c5f949ce8ed22ab3795f1883
-rw-r--r--runtime/jdwp/jdwp_socket.cc22
1 files changed, 16 insertions, 6 deletions
diff --git a/runtime/jdwp/jdwp_socket.cc b/runtime/jdwp/jdwp_socket.cc
index 2a00f05d4f..1bc58ac4e8 100644
--- a/runtime/jdwp/jdwp_socket.cc
+++ b/runtime/jdwp/jdwp_socket.cc
@@ -276,7 +276,12 @@ bool JdwpSocketState::Establish(const JdwpOptions* options) {
*/
#if defined(__linux__)
hostent he;
- char auxBuf[256];
+ // The size of the work buffer used in the gethostbyname_r call
+ // below. It used to be 128, but this was not enough on some
+ // configurations (maybe because of IPv6?), causing failures in JDWP
+ // host testing; thus it was increased to 256.
+ static constexpr size_t kAuxBufSize = 256;
+ char auxBuf[kAuxBufSize];
int error;
int cc = gethostbyname_r(options->host.c_str(), &he, auxBuf, sizeof(auxBuf), &pEntry, &error);
if (cc != 0) {
@@ -298,7 +303,8 @@ bool JdwpSocketState::Establish(const JdwpOptions* options) {
addr.addrInet.sin_port = htons(options->port);
- LOG(INFO) << "Connecting out to " << inet_ntoa(addr.addrInet.sin_addr) << ":" << ntohs(addr.addrInet.sin_port);
+ LOG(INFO) << "Connecting out to " << inet_ntoa(addr.addrInet.sin_addr) << ":"
+ << ntohs(addr.addrInet.sin_port);
/*
* Create a socket.
@@ -313,13 +319,15 @@ bool JdwpSocketState::Establish(const JdwpOptions* options) {
* Try to connect.
*/
if (connect(clientSock, &addr.addrPlain, sizeof(addr)) != 0) {
- PLOG(ERROR) << "Unable to connect to " << inet_ntoa(addr.addrInet.sin_addr) << ":" << ntohs(addr.addrInet.sin_port);
+ PLOG(ERROR) << "Unable to connect to " << inet_ntoa(addr.addrInet.sin_addr) << ":"
+ << ntohs(addr.addrInet.sin_port);
close(clientSock);
clientSock = -1;
return false;
}
- LOG(INFO) << "Connection established to " << options->host << " (" << inet_ntoa(addr.addrInet.sin_addr) << ":" << ntohs(addr.addrInet.sin_port) << ")";
+ LOG(INFO) << "Connection established to " << options->host << " ("
+ << inet_ntoa(addr.addrInet.sin_addr) << ":" << ntohs(addr.addrInet.sin_port) << ")";
SetAwaitingHandshake(true);
input_count_ = 0;
@@ -438,7 +446,8 @@ bool JdwpSocketState::ProcessIncoming() {
}
}
if (clientSock >= 0 && FD_ISSET(clientSock, &readfds)) {
- readCount = read(clientSock, input_buffer_ + input_count_, sizeof(input_buffer_) - input_count_);
+ readCount =
+ read(clientSock, input_buffer_ + input_count_, sizeof(input_buffer_) - input_count_);
if (readCount < 0) {
/* read failed */
if (errno != EINTR) {
@@ -479,7 +488,8 @@ bool JdwpSocketState::ProcessIncoming() {
errno = 0;
int cc = TEMP_FAILURE_RETRY(write(clientSock, input_buffer_, kMagicHandshakeLen));
if (cc != kMagicHandshakeLen) {
- PLOG(ERROR) << "Failed writing handshake bytes (" << cc << " of " << kMagicHandshakeLen << ")";
+ PLOG(ERROR) << "Failed writing handshake bytes ("
+ << cc << " of " << kMagicHandshakeLen << ")";
goto fail;
}