Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7651eb9e authored by Josh Gao's avatar Josh Gao
Browse files

adb: try harder to fill our test sockets.

On platforms that implement sockets via underlying sockets (e.g. Wine),
a socket can appear to be full, and then become available for writes
again without read being called on the other end. Add a sleep after
each write to give the underlying implementation time to flush.

This doesn't help us if the buffer size is smaller than MAX_PAYLOAD,
but at least in the case of Wine, that doesn't seem to be the case.

Test: adb_test
Test: wine adb_test.exe
Change-Id: Iff1ec14bbf318b9742ec7e2fb72e34e3d6bbe6ad
parent 954e1280
Loading
Loading
Loading
Loading
+19 −5
Original line number Original line Diff line number Diff line
@@ -112,11 +112,25 @@ static void CreateCloser(CloseWithPacketArg* arg) {
        ASSERT_TRUE(s != nullptr);
        ASSERT_TRUE(s != nullptr);
        arg->bytes_written = 0;
        arg->bytes_written = 0;


        // On platforms that implement sockets via underlying sockets (e.g. Wine),
        // a socket can appear to be full, and then become available for writes
        // again without read being called on the other end. Loop and sleep after
        // each write to give the underlying implementation time to flush.
        bool socket_filled = false;
        for (int i = 0; i < 128; ++i) {
            std::string data;
            std::string data;
            data.resize(MAX_PAYLOAD);
            data.resize(MAX_PAYLOAD);
            arg->bytes_written += data.size();
            arg->bytes_written += data.size();
            int ret = s->enqueue(s, std::move(data));
            int ret = s->enqueue(s, std::move(data));
        ASSERT_EQ(1, ret);
            if (ret == 1) {
                socket_filled = true;
                break;
            }
            ASSERT_NE(-1, ret);

            std::this_thread::sleep_for(250ms);
        }
        ASSERT_TRUE(socket_filled);


        asocket* cause_close_s = create_local_socket(arg->cause_close_fd);
        asocket* cause_close_s = create_local_socket(arg->cause_close_fd);
        ASSERT_TRUE(cause_close_s != nullptr);
        ASSERT_TRUE(cause_close_s != nullptr);