Linux + iPhone Continuity / iMessage / SMS
Code review feedback
sfreeman422353827864432
diff --git a/src/core/src/event_loop.cpp b/src/core/src/event_loop.cppindex 705754f..430188f 100644--- a/src/core/src/event_loop.cpp+++ b/src/core/src/event_loop.cpp@@ -107,6 +107,14 @@ namespace tether {}}- void EpollEventLoop::stop() { running_ = false; }+ void EpollEventLoop::stop() {+ running_ = false;+ if (post_fd_ >= 0) {+ uint64_t one = 1;+ if (write(post_fd_, &one, sizeof(one)) < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {+ debug::log(ERR, "Failed to wake the event loop during stop");+ }+ }+ }} // namespace tetherdiff --git a/test/test_event_loop.cpp b/test/test_event_loop.cppindex b4d60ee..7ec3683 100644--- a/test/test_event_loop.cpp+++ b/test/test_event_loop.cpp@@ -2,6 +2,8 @@#include <tether/event_loop.hpp>#include <atomic>+#include <chrono>+#include <future>#include <thread>using namespace tether;@@ -39,3 +41,13 @@ TEST(EventLoopTest, RunsWorkPostedBeforeRun) {EXPECT_TRUE(ran);}++TEST(EventLoopTest, StopFromAnotherThreadWakesTheLoop) {+ EpollEventLoop loop;+ auto run_future = std::async(std::launch::async, [&] { loop.run(); });++ std::this_thread::sleep_for(std::chrono::milliseconds(50));+ loop.stop();++ EXPECT_EQ(run_future.wait_for(std::chrono::seconds(2)), std::future_status::ready);+}diff --git a/test/test_net.cpp b/test/test_net.cppindex 5e1184e..ac3f9a0 100644--- a/test/test_net.cpp+++ b/test/test_net.cpp@@ -152,17 +152,14 @@ namespace {public:EventLoopGuard(tether::EpollEventLoop* loop) : loop_(loop) {}~EventLoopGuard() {- if (loop_) {- loop_->post([this] { loop_->stop(); });- }+ if (loop_)+ loop_->stop();}private:tether::EpollEventLoop* loop_;};- // A failed handshake used to close the socket with no trace at all, so a phone- // stuck in a connect/retry loop looked identical to a phone that never called.TEST(TcpServerTest, ReportsWhyATlsHandshakeFailed) {const std::string home = "/tmp/tether_net_test";CleanupGuard cleanup_guard(home);@@ -189,9 +186,10 @@ namespace {addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);ASSERT_EQ(connect(client, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)), 0);- // Plain text where a TLS ClientHello belongs.const char garbage[] = "this is not a tls client hello\n";ASSERT_GT(write(client, garbage, sizeof(garbage) - 1), 0);+ shutdown(client, SHUT_RDWR);+ close(client);std::string log;for (int attempt = 0; attempt < 200; ++attempt) {@@ -201,7 +199,7 @@ namespace {std::this_thread::sleep_for(std::chrono::milliseconds(10));}- close(client);+ loop.stop();loop_thread.join();captured.restore();