Loading adb/adb.cpp +4 −1 Original line number Original line Diff line number Diff line Loading @@ -30,7 +30,9 @@ #include <sys/time.h> #include <sys/time.h> #include <time.h> #include <time.h> #include <chrono> #include <string> #include <string> #include <thread> #include <vector> #include <vector> #include <android-base/errors.h> #include <android-base/errors.h> Loading @@ -51,6 +53,7 @@ #include <sys/capability.h> #include <sys/capability.h> #include <sys/mount.h> #include <sys/mount.h> #include <android-base/properties.h> #include <android-base/properties.h> using namespace std::chrono_literals; #endif #endif std::string adb_version() { std::string adb_version() { Loading Loading @@ -375,7 +378,7 @@ void handle_packet(apacket *p, atransport *t) adbd_auth_verified(t); adbd_auth_verified(t); t->failed_auth_attempts = 0; t->failed_auth_attempts = 0; } else { } else { if (t->failed_auth_attempts++ > 256) adb_sleep_ms(1000); if (t->failed_auth_attempts++ > 256) std::this_thread::sleep_for(1s); send_auth_request(t); send_auth_request(t); } } break; break; Loading adb/adb_client.cpp +5 −3 Original line number Original line Diff line number Diff line Loading @@ -28,7 +28,9 @@ #include <sys/stat.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/types.h> #include <chrono> #include <string> #include <string> #include <thread> #include <vector> #include <vector> #include <android-base/stringprintf.h> #include <android-base/stringprintf.h> Loading Loading @@ -188,8 +190,8 @@ int adb_connect(const std::string& service, std::string* error) { } else { } else { fprintf(stdout,"* daemon started successfully *\n"); fprintf(stdout,"* daemon started successfully *\n"); } } /* give the server some time to start properly and detect devices */ // Give the server some time to start properly and detect devices. adb_sleep_ms(3000); std::this_thread::sleep_for(std::chrono::seconds(3)); // fall through to _adb_connect // fall through to _adb_connect } else { } else { // If a server is already running, check its version matches. // If a server is already running, check its version matches. Loading Loading @@ -234,7 +236,7 @@ int adb_connect(const std::string& service, std::string* error) { } } /* XXX can we better detect its death? */ /* XXX can we better detect its death? */ adb_sleep_ms(2000); std::this_thread::sleep_for(std::chrono::seconds(2)); goto start_server; goto start_server; } } } } Loading adb/adb_io.cpp +4 −1 Original line number Original line Diff line number Diff line Loading @@ -20,6 +20,9 @@ #include <unistd.h> #include <unistd.h> #include <chrono> #include <thread> #include <android-base/stringprintf.h> #include <android-base/stringprintf.h> #include "adb.h" #include "adb.h" Loading Loading @@ -104,7 +107,7 @@ bool WriteFdExactly(int fd, const void* buf, size_t len) { if (r == -1) { if (r == -1) { D("writex: fd=%d error %d: %s", fd, errno, strerror(errno)); D("writex: fd=%d error %d: %s", fd, errno, strerror(errno)); if (errno == EAGAIN) { if (errno == EAGAIN) { adb_sleep_ms(1); // just yield some cpu time std::this_thread::yield(); continue; continue; } else if (errno == EPIPE) { } else if (errno == EPIPE) { D("writex: fd=%d disconnected", fd); D("writex: fd=%d disconnected", fd); Loading adb/commandline.cpp +3 −1 Original line number Original line Diff line number Diff line Loading @@ -31,8 +31,10 @@ #include <sys/stat.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/types.h> #include <chrono> #include <memory> #include <memory> #include <string> #include <string> #include <thread> #include <vector> #include <vector> #include <android-base/file.h> #include <android-base/file.h> Loading Loading @@ -1080,7 +1082,7 @@ static bool adb_root(const char* command) { // Give adbd some time to kill itself and come back up. // Give adbd some time to kill itself and come back up. // We can't use wait-for-device because devices (e.g. adb over network) might not come back. // We can't use wait-for-device because devices (e.g. adb over network) might not come back. adb_sleep_ms(3000); std::this_thread::sleep_for(std::chrono::seconds(3)); return true; return true; } } Loading adb/socket_test.cpp +15 −13 Original line number Original line Diff line number Diff line Loading @@ -19,9 +19,11 @@ #include <gtest/gtest.h> #include <gtest/gtest.h> #include <array> #include <array> #include <chrono> #include <limits> #include <limits> #include <queue> #include <queue> #include <string> #include <string> #include <thread> #include <vector> #include <vector> #include <unistd.h> #include <unistd.h> Loading @@ -44,7 +46,7 @@ static void FdEventThreadFunc(void*) { fdevent_loop(); fdevent_loop(); } } const size_t SLEEP_FOR_FDEVENT_IN_MS = 100; constexpr auto SLEEP_FOR_FDEVENT = std::chrono::milliseconds(100); TEST_F(LocalSocketTest, smoke) { TEST_F(LocalSocketTest, smoke) { // Join two socketpairs with a chain of intermediate socketpairs. // Join two socketpairs with a chain of intermediate socketpairs. Loading Loading @@ -101,7 +103,7 @@ TEST_F(LocalSocketTest, smoke) { ASSERT_EQ(0, adb_close(last[1])); ASSERT_EQ(0, adb_close(last[1])); // Wait until the local sockets are closed. // Wait until the local sockets are closed. adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); TerminateThread(thread); TerminateThread(thread); } } Loading Loading @@ -154,12 +156,12 @@ TEST_F(LocalSocketTest, close_socket_with_packet) { ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(CloseWithPacketThreadFunc), ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(CloseWithPacketThreadFunc), &arg, &thread)); &arg, &thread)); // Wait until the fdevent_loop() starts. // Wait until the fdevent_loop() starts. adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(0, adb_close(cause_close_fd[0])); ASSERT_EQ(0, adb_close(cause_close_fd[0])); adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(0, adb_close(socket_fd[0])); ASSERT_EQ(0, adb_close(socket_fd[0])); adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); TerminateThread(thread); TerminateThread(thread); } } Loading @@ -179,9 +181,9 @@ TEST_F(LocalSocketTest, read_from_closing_socket) { ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(CloseWithPacketThreadFunc), ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(CloseWithPacketThreadFunc), &arg, &thread)); &arg, &thread)); // Wait until the fdevent_loop() starts. // Wait until the fdevent_loop() starts. adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(0, adb_close(cause_close_fd[0])); ASSERT_EQ(0, adb_close(cause_close_fd[0])); adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); // Verify if we can read successfully. // Verify if we can read successfully. Loading @@ -190,7 +192,7 @@ TEST_F(LocalSocketTest, read_from_closing_socket) { ASSERT_EQ(true, ReadFdExactly(socket_fd[0], buf.data(), buf.size())); ASSERT_EQ(true, ReadFdExactly(socket_fd[0], buf.data(), buf.size())); ASSERT_EQ(0, adb_close(socket_fd[0])); ASSERT_EQ(0, adb_close(socket_fd[0])); adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); TerminateThread(thread); TerminateThread(thread); } } Loading @@ -214,11 +216,11 @@ TEST_F(LocalSocketTest, write_error_when_having_packets) { &arg, &thread)); &arg, &thread)); // Wait until the fdevent_loop() starts. // Wait until the fdevent_loop() starts. adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); EXPECT_EQ(2u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); EXPECT_EQ(2u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(0, adb_close(socket_fd[0])); ASSERT_EQ(0, adb_close(socket_fd[0])); adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); TerminateThread(thread); TerminateThread(thread); } } Loading @@ -229,7 +231,7 @@ static void ClientThreadFunc() { std::string error; std::string error; int fd = network_loopback_client(5038, SOCK_STREAM, &error); int fd = network_loopback_client(5038, SOCK_STREAM, &error); ASSERT_GE(fd, 0) << error; ASSERT_GE(fd, 0) << error; adb_sleep_ms(200); std::this_thread::sleep_for(std::chrono::milliseconds(200)); ASSERT_EQ(0, adb_close(fd)); ASSERT_EQ(0, adb_close(fd)); } } Loading Loading @@ -265,13 +267,13 @@ TEST_F(LocalSocketTest, close_socket_in_CLOSE_WAIT_state) { &arg, &thread)); &arg, &thread)); // Wait until the fdevent_loop() starts. // Wait until the fdevent_loop() starts. adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); // Wait until the client closes its socket. // Wait until the client closes its socket. ASSERT_TRUE(adb_thread_join(client_thread)); ASSERT_TRUE(adb_thread_join(client_thread)); adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); TerminateThread(thread); TerminateThread(thread); } } Loading Loading
adb/adb.cpp +4 −1 Original line number Original line Diff line number Diff line Loading @@ -30,7 +30,9 @@ #include <sys/time.h> #include <sys/time.h> #include <time.h> #include <time.h> #include <chrono> #include <string> #include <string> #include <thread> #include <vector> #include <vector> #include <android-base/errors.h> #include <android-base/errors.h> Loading @@ -51,6 +53,7 @@ #include <sys/capability.h> #include <sys/capability.h> #include <sys/mount.h> #include <sys/mount.h> #include <android-base/properties.h> #include <android-base/properties.h> using namespace std::chrono_literals; #endif #endif std::string adb_version() { std::string adb_version() { Loading Loading @@ -375,7 +378,7 @@ void handle_packet(apacket *p, atransport *t) adbd_auth_verified(t); adbd_auth_verified(t); t->failed_auth_attempts = 0; t->failed_auth_attempts = 0; } else { } else { if (t->failed_auth_attempts++ > 256) adb_sleep_ms(1000); if (t->failed_auth_attempts++ > 256) std::this_thread::sleep_for(1s); send_auth_request(t); send_auth_request(t); } } break; break; Loading
adb/adb_client.cpp +5 −3 Original line number Original line Diff line number Diff line Loading @@ -28,7 +28,9 @@ #include <sys/stat.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/types.h> #include <chrono> #include <string> #include <string> #include <thread> #include <vector> #include <vector> #include <android-base/stringprintf.h> #include <android-base/stringprintf.h> Loading Loading @@ -188,8 +190,8 @@ int adb_connect(const std::string& service, std::string* error) { } else { } else { fprintf(stdout,"* daemon started successfully *\n"); fprintf(stdout,"* daemon started successfully *\n"); } } /* give the server some time to start properly and detect devices */ // Give the server some time to start properly and detect devices. adb_sleep_ms(3000); std::this_thread::sleep_for(std::chrono::seconds(3)); // fall through to _adb_connect // fall through to _adb_connect } else { } else { // If a server is already running, check its version matches. // If a server is already running, check its version matches. Loading Loading @@ -234,7 +236,7 @@ int adb_connect(const std::string& service, std::string* error) { } } /* XXX can we better detect its death? */ /* XXX can we better detect its death? */ adb_sleep_ms(2000); std::this_thread::sleep_for(std::chrono::seconds(2)); goto start_server; goto start_server; } } } } Loading
adb/adb_io.cpp +4 −1 Original line number Original line Diff line number Diff line Loading @@ -20,6 +20,9 @@ #include <unistd.h> #include <unistd.h> #include <chrono> #include <thread> #include <android-base/stringprintf.h> #include <android-base/stringprintf.h> #include "adb.h" #include "adb.h" Loading Loading @@ -104,7 +107,7 @@ bool WriteFdExactly(int fd, const void* buf, size_t len) { if (r == -1) { if (r == -1) { D("writex: fd=%d error %d: %s", fd, errno, strerror(errno)); D("writex: fd=%d error %d: %s", fd, errno, strerror(errno)); if (errno == EAGAIN) { if (errno == EAGAIN) { adb_sleep_ms(1); // just yield some cpu time std::this_thread::yield(); continue; continue; } else if (errno == EPIPE) { } else if (errno == EPIPE) { D("writex: fd=%d disconnected", fd); D("writex: fd=%d disconnected", fd); Loading
adb/commandline.cpp +3 −1 Original line number Original line Diff line number Diff line Loading @@ -31,8 +31,10 @@ #include <sys/stat.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/types.h> #include <chrono> #include <memory> #include <memory> #include <string> #include <string> #include <thread> #include <vector> #include <vector> #include <android-base/file.h> #include <android-base/file.h> Loading Loading @@ -1080,7 +1082,7 @@ static bool adb_root(const char* command) { // Give adbd some time to kill itself and come back up. // Give adbd some time to kill itself and come back up. // We can't use wait-for-device because devices (e.g. adb over network) might not come back. // We can't use wait-for-device because devices (e.g. adb over network) might not come back. adb_sleep_ms(3000); std::this_thread::sleep_for(std::chrono::seconds(3)); return true; return true; } } Loading
adb/socket_test.cpp +15 −13 Original line number Original line Diff line number Diff line Loading @@ -19,9 +19,11 @@ #include <gtest/gtest.h> #include <gtest/gtest.h> #include <array> #include <array> #include <chrono> #include <limits> #include <limits> #include <queue> #include <queue> #include <string> #include <string> #include <thread> #include <vector> #include <vector> #include <unistd.h> #include <unistd.h> Loading @@ -44,7 +46,7 @@ static void FdEventThreadFunc(void*) { fdevent_loop(); fdevent_loop(); } } const size_t SLEEP_FOR_FDEVENT_IN_MS = 100; constexpr auto SLEEP_FOR_FDEVENT = std::chrono::milliseconds(100); TEST_F(LocalSocketTest, smoke) { TEST_F(LocalSocketTest, smoke) { // Join two socketpairs with a chain of intermediate socketpairs. // Join two socketpairs with a chain of intermediate socketpairs. Loading Loading @@ -101,7 +103,7 @@ TEST_F(LocalSocketTest, smoke) { ASSERT_EQ(0, adb_close(last[1])); ASSERT_EQ(0, adb_close(last[1])); // Wait until the local sockets are closed. // Wait until the local sockets are closed. adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); TerminateThread(thread); TerminateThread(thread); } } Loading Loading @@ -154,12 +156,12 @@ TEST_F(LocalSocketTest, close_socket_with_packet) { ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(CloseWithPacketThreadFunc), ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(CloseWithPacketThreadFunc), &arg, &thread)); &arg, &thread)); // Wait until the fdevent_loop() starts. // Wait until the fdevent_loop() starts. adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(0, adb_close(cause_close_fd[0])); ASSERT_EQ(0, adb_close(cause_close_fd[0])); adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(0, adb_close(socket_fd[0])); ASSERT_EQ(0, adb_close(socket_fd[0])); adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); TerminateThread(thread); TerminateThread(thread); } } Loading @@ -179,9 +181,9 @@ TEST_F(LocalSocketTest, read_from_closing_socket) { ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(CloseWithPacketThreadFunc), ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(CloseWithPacketThreadFunc), &arg, &thread)); &arg, &thread)); // Wait until the fdevent_loop() starts. // Wait until the fdevent_loop() starts. adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(0, adb_close(cause_close_fd[0])); ASSERT_EQ(0, adb_close(cause_close_fd[0])); adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); // Verify if we can read successfully. // Verify if we can read successfully. Loading @@ -190,7 +192,7 @@ TEST_F(LocalSocketTest, read_from_closing_socket) { ASSERT_EQ(true, ReadFdExactly(socket_fd[0], buf.data(), buf.size())); ASSERT_EQ(true, ReadFdExactly(socket_fd[0], buf.data(), buf.size())); ASSERT_EQ(0, adb_close(socket_fd[0])); ASSERT_EQ(0, adb_close(socket_fd[0])); adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); TerminateThread(thread); TerminateThread(thread); } } Loading @@ -214,11 +216,11 @@ TEST_F(LocalSocketTest, write_error_when_having_packets) { &arg, &thread)); &arg, &thread)); // Wait until the fdevent_loop() starts. // Wait until the fdevent_loop() starts. adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); EXPECT_EQ(2u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); EXPECT_EQ(2u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(0, adb_close(socket_fd[0])); ASSERT_EQ(0, adb_close(socket_fd[0])); adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); TerminateThread(thread); TerminateThread(thread); } } Loading @@ -229,7 +231,7 @@ static void ClientThreadFunc() { std::string error; std::string error; int fd = network_loopback_client(5038, SOCK_STREAM, &error); int fd = network_loopback_client(5038, SOCK_STREAM, &error); ASSERT_GE(fd, 0) << error; ASSERT_GE(fd, 0) << error; adb_sleep_ms(200); std::this_thread::sleep_for(std::chrono::milliseconds(200)); ASSERT_EQ(0, adb_close(fd)); ASSERT_EQ(0, adb_close(fd)); } } Loading Loading @@ -265,13 +267,13 @@ TEST_F(LocalSocketTest, close_socket_in_CLOSE_WAIT_state) { &arg, &thread)); &arg, &thread)); // Wait until the fdevent_loop() starts. // Wait until the fdevent_loop() starts. adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count()); // Wait until the client closes its socket. // Wait until the client closes its socket. ASSERT_TRUE(adb_thread_join(client_thread)); ASSERT_TRUE(adb_thread_join(client_thread)); adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS); std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); TerminateThread(thread); TerminateThread(thread); } } Loading