Merge changes I0ee130db,I33d356fd am: e461b37965 am: 59561a64b7

am: 87ff463d6e

Change-Id: I72ac706e6866b6f391cc950a677a598df79fa9a0
This commit is contained in:
Josh Gao 2016-08-25 02:09:55 +00:00 committed by android-build-merger
commit 7424dfa361
6 changed files with 36 additions and 25 deletions

View file

@ -151,9 +151,7 @@ void adb_auth_confirm_key(unsigned char* key, size_t len, atransport* t) {
}
static void adb_auth_listener(int fd, unsigned events, void* data) {
sockaddr_storage addr;
socklen_t alen = sizeof(addr);
int s = adb_socket_accept(fd, reinterpret_cast<sockaddr*>(&addr), &alen);
int s = adb_socket_accept(fd, nullptr, nullptr);
if (s < 0) {
PLOG(ERROR) << "Failed to accept";
return;

View file

@ -71,10 +71,7 @@ static ListenerList& listener_list = *new ListenerList();
static void ss_listener_event_func(int _fd, unsigned ev, void *_l) {
if (ev & FDE_READ) {
sockaddr_storage ss;
sockaddr* addrp = reinterpret_cast<sockaddr*>(&ss);
socklen_t alen = sizeof(ss);
int fd = adb_socket_accept(_fd, addrp, &alen);
int fd = adb_socket_accept(_fd, nullptr, nullptr);
if (fd < 0) return;
int rcv_buf_size = CHUNK_SIZE;
@ -96,13 +93,7 @@ static void listener_event_func(int _fd, unsigned ev, void* _l)
asocket *s;
if (ev & FDE_READ) {
sockaddr_storage ss;
sockaddr* addrp = reinterpret_cast<sockaddr*>(&ss);
socklen_t alen;
int fd;
alen = sizeof(ss);
fd = adb_socket_accept(_fd, addrp, &alen);
int fd = adb_socket_accept(_fd, nullptr, nullptr);
if (fd < 0) {
return;
}

View file

@ -444,10 +444,7 @@ static void jdwp_control_event(int s, unsigned events, void* _control) {
JdwpControl* control = (JdwpControl*)_control;
if (events & FDE_READ) {
sockaddr_storage ss;
sockaddr* addrp = reinterpret_cast<sockaddr*>(&ss);
socklen_t addrlen = sizeof(ss);
int s = adb_socket_accept(control->listen_socket, addrp, &addrlen);
int s = adb_socket_accept(control->listen_socket, nullptr, nullptr);
if (s < 0) {
if (errno == ECONNABORTED) {
/* oops, the JDWP process died really quick */

View file

@ -285,6 +285,10 @@ extern int adb_socket_accept(int serverfd, struct sockaddr* addr, socklen_t
#undef accept
#define accept ___xxx_accept
int adb_getsockname(int fd, struct sockaddr* sockaddr, socklen_t* optlen);
#undef getsockname
#define getsockname(...) ___xxx_getsockname(__VA__ARGS__)
// Returns the local port number of a bound socket, or -1 on failure.
int adb_socket_get_local_port(int fd);

View file

@ -1061,7 +1061,7 @@ int adb_getsockname(int fd, struct sockaddr* sockaddr, socklen_t* optlen) {
return -1;
}
int result = getsockname(fh->fh_socket, sockaddr, optlen);
int result = (getsockname)(fh->fh_socket, sockaddr, optlen);
if (result == SOCKET_ERROR) {
const DWORD err = WSAGetLastError();
D("adb_getsockname: setsockopt on fd %d failed: %s\n", fd,
@ -1119,6 +1119,11 @@ int adb_socketpair(int sv[2]) {
int local_port = -1;
std::string error;
struct sockaddr_storage peer_addr = {};
struct sockaddr_storage client_addr = {};
socklen_t peer_socklen = sizeof(peer_addr);
socklen_t client_socklen = sizeof(client_addr);
server = network_loopback_server(0, SOCK_STREAM, &error);
if (server < 0) {
D("adb_socketpair: failed to create server: %s", error.c_str());
@ -1138,12 +1143,32 @@ int adb_socketpair(int sv[2]) {
goto fail;
}
accepted = adb_socket_accept(server, nullptr, nullptr);
// Make sure that the peer that connected to us and the client are the same.
accepted = adb_socket_accept(server, reinterpret_cast<sockaddr*>(&peer_addr), &peer_socklen);
if (accepted < 0) {
D("adb_socketpair: failed to accept: %s", strerror(errno));
goto fail;
}
if (adb_getsockname(client, reinterpret_cast<sockaddr*>(&client_addr), &client_socklen) != 0) {
D("adb_socketpair: failed to getpeername: %s", strerror(errno));
goto fail;
}
if (peer_socklen != client_socklen) {
D("adb_socketpair: client and peer sockaddrs have different lengths");
errno = EIO;
goto fail;
}
if (memcmp(&peer_addr, &client_addr, peer_socklen) != 0) {
D("adb_socketpair: client and peer sockaddrs don't match");
errno = EIO;
goto fail;
}
adb_close(server);
sv[0] = client;
sv[1] = accepted;
return 0;

View file

@ -202,9 +202,6 @@ static void client_socket_thread(void* x) {
static void server_socket_thread(void* arg) {
int serverfd, fd;
sockaddr_storage ss;
sockaddr *addrp = reinterpret_cast<sockaddr*>(&ss);
socklen_t alen;
int port = (int) (uintptr_t) arg;
adb_thread_setname("server socket");
@ -222,9 +219,8 @@ static void server_socket_thread(void* arg) {
close_on_exec(serverfd);
}
alen = sizeof(ss);
D("server: trying to get new connection from %d", port);
fd = adb_socket_accept(serverfd, addrp, &alen);
fd = adb_socket_accept(serverfd, nullptr, nullptr);
if(fd >= 0) {
D("server: new connection on fd %d", fd);
close_on_exec(fd);