diff --git a/Common/Cpp/Sockets/AbstractServerSocket.h b/Common/Cpp/Sockets/AbstractServerSocket.h index 7a0c1a28a8..a7a11783e6 100644 --- a/Common/Cpp/Sockets/AbstractServerSocket.h +++ b/Common/Cpp/Sockets/AbstractServerSocket.h @@ -85,30 +85,16 @@ class AbstractServerSocket{ // State::LISTENING on success or State::NOT_RUNNING on failure. virtual void start(const std::string& address, uint16_t port) = 0; - // Closes the active connection, if any, and keeps listening. It does - // not wait for the worker threads, so it is safe to call from within - // a listener callback. "Listener::on_disconnect" is not called for - // the connection closed this way. + // Closes the active connection, if any, and keeps listening. Unlike + // the full teardown the destructor performs, this does not wait for + // the worker threads, so it is safe to call from within a listener + // callback. "Listener::on_disconnect" is not called for the + // connection closed this way. // - // It cancels any in-flight "send()" the same way "close()" does: the - // send returns promptly with the number of bytes actually written so - // far (best effort). + // It cancels any in-flight "send()": the send returns promptly with + // the number of bytes actually written so far (best effort). virtual void close_connection() = 0; - // Requests immediate teardown of the server, without waiting for the - // worker threads to exit. This is safe to call from within a listener - // callback (which runs on one of those threads; a blocking teardown - // there would deadlock). It marks the server DESTRUCTING (no new - // connections are accepted), closes the active connection, and - // cancels any in-flight "send()": its caller returns promptly with - // the number of bytes actually written so far (best effort). No - // "on_disconnect" callback is fired. The server is left in - // State::DESTRUCTING; its destructor completes the teardown (joins - // the threads and returns it to NOT_RUNNING), and so does a later - // "start()" on the same server, so it can be reused or destroyed. It - // is safe to call multiple times. - virtual void close() noexcept = 0; - // Sends data to the active connection. This blocks until every byte // has been written, the connection is lost, "close()"/ // "close_connection()" is called, or "timeout" elapses. diff --git a/Common/Cpp/Sockets/ServerSocket_POSIX.cpp b/Common/Cpp/Sockets/ServerSocket_POSIX.cpp index c17fb5d75a..47736e751b 100644 --- a/Common/Cpp/Sockets/ServerSocket_POSIX.cpp +++ b/Common/Cpp/Sockets/ServerSocket_POSIX.cpp @@ -30,14 +30,6 @@ ServerSocket_POSIX::ServerSocket_POSIX(ThreadPool& thread_pool) } void ServerSocket_POSIX::start(const std::string& address, uint16_t port){ - // Complete a requested-but-unfinished close() before starting a new - // listener: close() is non-blocking (it leaves the server DESTRUCTING - // with the threads still exiting), so re-listening on the same server - // joins them here. No-op if the server is already NOT_RUNNING. - // start() is always user-initiated, never a callback, so blocking is - // safe. - close_and_wait(); - uint64_t generation = 0; { std::lock_guard lg(m_lock); @@ -67,7 +59,7 @@ void ServerSocket_POSIX::start(const std::string& address, uint16_t port){ // caller's wait timed out while the pool was starved). It // notices its stale generation when it gets scheduled and // exits without listening, so it only has to outlive this - // call; close_and_wait() joins the whole list. + // call; close() joins the whole list. std::lock_guard lg(m_task_lock); m_accept_threads.push_back(std::move(task)); } @@ -110,25 +102,6 @@ void ServerSocket_POSIX::close_connection(){ } void ServerSocket_POSIX::close() noexcept{ - // Non-blocking teardown, safe to call from within a listener callback - // (which runs on one of the threads this would otherwise have to - // join). The accept loop and the connection loop observe - // State::DESTRUCTING on their next iteration (a few milliseconds) and - // exit on their own, closing their sockets; the server is left in - // State::DESTRUCTING. The blocking "close_and_wait()" - driven by the - // destructor and by a later "start()" on the same object - joins the - // threads and returns it to NOT_RUNNING. - { - std::lock_guard lg(m_lock); - if (m_state.load(std::memory_order_relaxed) != State::NOT_RUNNING){ - m_close_requested = true; - m_state.store(State::DESTRUCTING, std::memory_order_release); - } - } - m_cv.notify_all(); -} - -void ServerSocket_POSIX::close_and_wait() noexcept{ { std::unique_lock lg(m_lock); // Wait for an in-progress start() to publish the listener task @@ -148,7 +121,7 @@ void ServerSocket_POSIX::close_and_wait() noexcept{ } if (!drain){ // Either nothing was running (m_closing == 0), or another - // close_and_wait() is already draining the threads (m_closing > 1). + // close() is already draining the threads (m_closing > 1). // In the second case, wait for it to finish. std::unique_lock lg(m_lock); m_cv.wait(lg, [&]{ diff --git a/Common/Cpp/Sockets/ServerSocket_POSIX.h b/Common/Cpp/Sockets/ServerSocket_POSIX.h index 8cd8ec7746..844ab79f93 100644 --- a/Common/Cpp/Sockets/ServerSocket_POSIX.h +++ b/Common/Cpp/Sockets/ServerSocket_POSIX.h @@ -27,7 +27,7 @@ class ServerSocket_POSIX final : public AbstractServerSocket{ ServerSocket_POSIX(ThreadPool& thread_pool); virtual ~ServerSocket_POSIX(){ - close_and_wait(); + close(); } virtual void start(const std::string& address, uint16_t port) override; @@ -39,16 +39,6 @@ class ServerSocket_POSIX final : public AbstractServerSocket{ // within a listener callback. virtual void close_connection() override; - // Requests immediate teardown of the server, without waiting for the - // worker threads to exit. It marks the server DESTRUCTING and closes - // the active connection; the accept and connection threads observe - // the new state on their next iteration and exit on their own, closing - // their sockets. It cancels any in-flight "send()" the same way - // "close_connection()" does. Safe to call from within a listener - // callback. The blocking "close_and_wait()" (the destructor, and the - // "start()" prelude) joins the threads and returns NOT_RUNNING. - virtual void close() noexcept override; - virtual size_t send( const void* data, size_t bytes, @@ -58,11 +48,11 @@ class ServerSocket_POSIX final : public AbstractServerSocket{ private: - // The blocking teardown: waits for an in-progress start() to publish - // its task, then joins the accept and connection threads and returns - // the server to NOT_RUNNING. Driven by the destructor and by start() - // (which re-listens on the same object after a close()). - void close_and_wait() noexcept; + // Stops the server: it stops accepting new connections, closes the + // active connection, and returns the server to State::NOT_RUNNING so + // the object is fully torn down. It blocks until the worker threads + // have exited, so it is private and only called by the destructor. + void close() noexcept; void accept_thread_loop(std::string address, uint16_t port, uint64_t generation); void connection_thread_loop(); @@ -100,8 +90,8 @@ class ServerSocket_POSIX final : public AbstractServerSocket{ // One task per start() call. start() must never destroy the previous // task's AsyncTask here: its destructor blocks until the task has // finished, and a task from an earlier attempt may still be running - // (the caller's wait timed out while the pool was starved). - // close_and_wait() joins the whole list. + // (the caller's wait timed out while the pool was starved). close() + // joins the whole list. std::vector m_accept_threads; AsyncTask m_client_thread; }; diff --git a/Common/Cpp/Sockets/ServerSocket_Qt.cpp b/Common/Cpp/Sockets/ServerSocket_Qt.cpp index 76d8312157..f2f9ddf37a 100644 --- a/Common/Cpp/Sockets/ServerSocket_Qt.cpp +++ b/Common/Cpp/Sockets/ServerSocket_Qt.cpp @@ -16,14 +16,6 @@ namespace PokemonAutomation{ void ServerSocket_Qt::start(const std::string& address, uint16_t port){ - // Complete a requested-but-unfinished close() before starting a new - // listener: close() is non-blocking (it leaves the server DESTRUCTING - // with the QTcpServer still alive), so re-listening on the same server - // destroys the old one here. No-op if the server is already - // NOT_RUNNING. start() is always user-initiated, never a callback, so - // blocking is safe. - close_and_wait(); - bool starting; { std::lock_guard lg(m_lock); @@ -33,7 +25,7 @@ void ServerSocket_Qt::start(const std::string& address, uint16_t port){ && !m_starting; // Only claim the "starting" flag when we actually start: a // rejected call (server already running or already started) must - // not leave "m_starting" true - "close_and_wait()" waits on + // not leave "m_starting" true - "close()" waits on // "!m_starting", so a stale flag would deadlock the destructor. // (This happens when a test's start-retry loop calls start() on // a server whose first listen failed: "m_server" is set even on @@ -74,8 +66,7 @@ void ServerSocket_Qt::start(const std::string& address, uint16_t port){ (m_state.load(std::memory_order_relaxed) == State::DESTRUCTING); m_server = server; if (destructing){ - // "close_and_wait()" is already in progress (from the - // destructor or a concurrent start()): it will destroy the + // "close()" is already in progress: it will destroy the // server we just created. Leave the state for it. }else{ listening = m_listen_error.empty(); @@ -92,9 +83,9 @@ void ServerSocket_Qt::start(const std::string& address, uint16_t port){ // exactly as it was before this start() (no "m_server", state // NOT_RUNNING), so the caller's start-retry loop can immediately // try another port. The other backends behave the same: a failed - // listen leaves no listener behind. If "close_and_wait()" raced - // us, it has already claimed "m_server", and the pool's lookup - // makes the second destruction a no-op. + // listen leaves no listener behind. If "close()" raced us, it has + // already claimed "m_server", and the pool's lookup makes the + // second destruction a no-op. GlobalThreadPools::qt_event_threadpool().remove_object(server); std::lock_guard lg(m_lock); m_server = nullptr; @@ -140,41 +131,6 @@ void ServerSocket_Qt::close_connection(){ } } void ServerSocket_Qt::close() noexcept{ - // Non-blocking teardown, safe to call from within a listener callback - // (which runs on the event thread; the blocking teardown there would - // deadlock). It marks the server DESTRUCTING (on_new_connection() - // stops accepting, and connection_lost() no longer reports), cancels - // the in-flight "send()" calls so their callers return promptly, and - // aborts the active connection on the event thread the same way - // "close_connection()" does - queued when called from another - // thread, so it runs as soon as the event loop next turns. It does - // not wait for any of that. The QTcpServer itself (the connection - // socket is its child) is destroyed by the blocking - // "close_and_wait()" - the destructor, and the "start()" prelude - - // which also returns the state to NOT_RUNNING. - { - std::lock_guard lg(m_lock); - if (m_server == nullptr && !m_starting){ - // Never started, or already closed. - return; - } - m_close_requested = true; - m_state.store(State::DESTRUCTING, std::memory_order_release); - } - - // Cancel the in-flight "send()" calls so their callers return - // promptly with the best-effort byte count. - cancel_inflight_sends(); - - // Abort the active connection, same event as "close_connection()". - // Deliberately no wait: close() must never block. If we are not on - // the event thread, the abort runs when the event loop next turns - // (or is discarded with the server, which is harmless: it only ever - // touches state under m_lock). - emit internal_close_connection(QSharedPointer::create()); -} - -void ServerSocket_Qt::close_and_wait() noexcept{ QTcpServer* server; { std::lock_guard lg(m_lock); @@ -333,8 +289,8 @@ void ServerSocket_Qt::on_new_connection(){ if (sock == nullptr){ break; } - // The connection socket lives with the server, so - // "close_and_wait()" destroys it on the event thread. + // The connection socket lives with the server, so "close()" + // destroys it on the event thread. sock->setParent(server); bool accepted; @@ -436,9 +392,9 @@ void ServerSocket_Qt::on_close_connection(QSharedPointer comple if (m_socket != nullptr){ m_close_requested = true; if (m_state.load(std::memory_order_relaxed) != State::DESTRUCTING){ - // A plain close_connection(): the server keeps running, - // so it goes back to LISTENING. A close() in progress - // already set DESTRUCTING: leave the state for it. + // The server keeps running, so it goes back to + // LISTENING. The destructor's close() may have set + // DESTRUCTING: leave the state for it. m_state.store(State::LISTENING, std::memory_order_release); } sock = m_socket; @@ -479,8 +435,7 @@ void ServerSocket_Qt::on_send(QSharedPointer send_data){ const char* ptr = send_data->packet.data(); size_t remaining = send_data->packet.size(); // The deadline keeps a client that never reads from pinning this - // event thread forever (which would also block - // "close_and_wait()"). + // event thread forever (which would also block "close()"). while ( remaining > 0 && sock->state() == QAbstractSocket::ConnectedState diff --git a/Common/Cpp/Sockets/ServerSocket_Qt.h b/Common/Cpp/Sockets/ServerSocket_Qt.h index 7c8b66c8dd..e95f14f01d 100644 --- a/Common/Cpp/Sockets/ServerSocket_Qt.h +++ b/Common/Cpp/Sockets/ServerSocket_Qt.h @@ -39,9 +39,8 @@ class ServerSocket_Qt final : public QObject, public AbstractServerSocket{ std::string packet; // The event-thread write loop stops at this deadline, so a send // that can never complete (a client that never reads) cannot pin - // the server's event thread forever and block - // "close_and_wait()". "max()" means no deadline (the infinite - // default). + // the server's event thread forever and block "close()". "max()" + // means no deadline (the infinite default). std::chrono::steady_clock::time_point deadline = std::chrono::steady_clock::time_point::max(); // The running byte count: the write loop updates it as it goes, // so "close()"/"close_connection()" cancelling the send mid-write @@ -70,7 +69,7 @@ class ServerSocket_Qt final : public QObject, public AbstractServerSocket{ ServerSocket_Qt(ThreadPool&){} virtual ~ServerSocket_Qt(){ - close_and_wait(); + close(); } // Binds to "address" and listens on "port" on the Qt event thread. This @@ -83,21 +82,6 @@ class ServerSocket_Qt final : public QObject, public AbstractServerSocket{ // effort). It is safe to call from within a listener callback. virtual void close_connection() override; - // Requests immediate teardown of the server, without waiting for the - // event thread. It marks the server DESTRUCTING (no new connections - // are accepted), cancels the in-flight "send()" calls so their - // callers return promptly with the bytes written so far (best - // effort), and aborts the active connection on the event thread the - // same way "close_connection()" does. It does not wait for any of - // that, so it is safe to call from within a listener callback (which - // runs on the event thread). No "on_disconnect" callback is fired. - // The QTcpServer itself (and the connection socket, its child) is - // destroyed by the blocking "close_and_wait()" - the destructor, and - // the "start()" prelude - which also returns the state to - // NOT_RUNNING. Calling "close()" when the server is not running is a - // no-op. It is safe to call multiple times. - virtual void close() noexcept override; - virtual size_t send( const void* data, size_t bytes, @@ -136,13 +120,13 @@ class ServerSocket_Qt final : public QObject, public AbstractServerSocket{ // runs (or is discarded with the server). void cancel_inflight_sends(); - // The blocking teardown: cancels the in-flight "send()" calls the - // same way close() does, waits for an in-progress start() to publish - // the server, destroys the QTcpServer (and its connection socket) on - // the event thread, and returns the state to NOT_RUNNING. Driven by - // the destructor and by start() (which re-listens on the same object - // after a close()). - void close_and_wait() noexcept; + // Stops the server: it destroys the QTcpServer (and its connection + // socket) on the event thread and returns the state to + // State::NOT_RUNNING, so the object is fully torn down. It blocks + // until the QTcpServer has been destroyed, so any in-flight listener + // callback is finished by the time it returns; it is private and + // only called by the destructor. + void close() noexcept; std::unique_ptr make_server(const std::string& address, uint16_t port); diff --git a/Common/Cpp/Sockets/ServerSocket_WinSocket.cpp b/Common/Cpp/Sockets/ServerSocket_WinSocket.cpp index 43d3635338..b269dc69a7 100644 --- a/Common/Cpp/Sockets/ServerSocket_WinSocket.cpp +++ b/Common/Cpp/Sockets/ServerSocket_WinSocket.cpp @@ -34,14 +34,6 @@ void ServerSocket_WinSocket::ensure_wsa_started(){ } void ServerSocket_WinSocket::start(const std::string& address, uint16_t port){ - // Complete a requested-but-unfinished close() before starting a new - // listener: close() is non-blocking (it leaves the server DESTRUCTING - // with the threads still exiting), so re-listening on the same server - // joins them here. No-op if the server is already NOT_RUNNING. - // start() is always user-initiated, never a callback, so blocking is - // safe. - close_and_wait(); - // Winsock has to be started before any of its functions can be // used. Call it here, on the calling thread, so it is done before // any socket is created (a client created right after "start()" @@ -78,7 +70,7 @@ void ServerSocket_WinSocket::start(const std::string& address, uint16_t port){ // caller's wait timed out while the pool was starved). It // notices its stale generation when it gets scheduled and // exits without listening, so it only has to outlive this - // call; close_and_wait() joins the whole list. + // call; close() joins the whole list. std::lock_guard lg(m_task_lock); m_accept_threads.push_back(std::move(task)); } @@ -121,25 +113,6 @@ void ServerSocket_WinSocket::close_connection(){ } void ServerSocket_WinSocket::close() noexcept{ - // Non-blocking teardown, safe to call from within a listener callback - // (which runs on one of the threads this would otherwise have to - // join). The accept loop and the connection loop observe - // State::DESTRUCTING on their next iteration (a few milliseconds) and - // exit on their own, closing their sockets; the server is left in - // State::DESTRUCTING. The blocking "close_and_wait()" - driven by the - // destructor and by a later "start()" on the same object - joins the - // threads and returns it to NOT_RUNNING. - { - std::lock_guard lg(m_lock); - if (m_state.load(std::memory_order_relaxed) != State::NOT_RUNNING){ - m_close_requested = true; - m_state.store(State::DESTRUCTING, std::memory_order_release); - } - } - m_cv.notify_all(); -} - -void ServerSocket_WinSocket::close_and_wait() noexcept{ { std::unique_lock lg(m_lock); // Wait for an in-progress start() to publish the listener task @@ -159,7 +132,7 @@ void ServerSocket_WinSocket::close_and_wait() noexcept{ } if (!drain){ // Either nothing was running (m_closing == 0), or another - // close_and_wait() is already draining the threads (m_closing > 1). + // close() is already draining the threads (m_closing > 1). // In the second case, wait for it to finish. std::unique_lock lg(m_lock); m_cv.wait(lg, [&]{ diff --git a/Common/Cpp/Sockets/ServerSocket_WinSocket.h b/Common/Cpp/Sockets/ServerSocket_WinSocket.h index adbdc9e9df..d81267fdd5 100644 --- a/Common/Cpp/Sockets/ServerSocket_WinSocket.h +++ b/Common/Cpp/Sockets/ServerSocket_WinSocket.h @@ -30,7 +30,7 @@ class ServerSocket_WinSocket final : public AbstractServerSocket{ : m_thread_pool(thread_pool) {} virtual ~ServerSocket_WinSocket(){ - close_and_wait(); + close(); } virtual void start(const std::string& address, uint16_t port) override; @@ -42,16 +42,6 @@ class ServerSocket_WinSocket final : public AbstractServerSocket{ // within a listener callback. virtual void close_connection() override; - // Requests immediate teardown of the server, without waiting for the - // worker threads to exit. It marks the server DESTRUCTING and closes - // the active connection; the accept and connection threads observe - // the new state on their next iteration and exit on their own, closing - // their sockets. It cancels any in-flight "send()" the same way - // "close_connection()" does. Safe to call from within a listener - // callback. The blocking "close_and_wait()" (the destructor, and the - // "start()" prelude) joins the threads and returns NOT_RUNNING. - virtual void close() noexcept override; - virtual size_t send( const void* data, size_t bytes, @@ -67,11 +57,11 @@ class ServerSocket_WinSocket final : public AbstractServerSocket{ // other parts of the process (Qt) may be using Winsock as well. static void ensure_wsa_started(); - // The blocking teardown: waits for an in-progress start() to publish - // its task, then joins the accept and connection threads and returns - // the server to NOT_RUNNING. Driven by the destructor and by start() - // (which re-listens on the same object after a close()). - void close_and_wait() noexcept; + // Stops the server: it stops accepting new connections, closes the + // active connection, and returns the server to State::NOT_RUNNING so + // the object is fully torn down. It blocks until the worker threads + // have exited, so it is private and only called by the destructor. + void close() noexcept; void accept_thread_loop(std::string address, uint16_t port, uint64_t generation); void connection_thread_loop(); @@ -109,8 +99,8 @@ class ServerSocket_WinSocket final : public AbstractServerSocket{ // One task per start() call. start() must never destroy the previous // task's AsyncTask here: its destructor blocks until the task has // finished, and a task from an earlier attempt may still be running - // (the caller's wait timed out while the pool was starved). - // close_and_wait() joins the whole list. + // (the caller's wait timed out while the pool was starved). close() + // joins the whole list. std::vector m_accept_threads; AsyncTask m_client_thread; }; diff --git a/Common/Cpp/Sockets/Sockets_Tests.cpp b/Common/Cpp/Sockets/Sockets_Tests.cpp index 061f1e379b..2446c7e7ef 100644 --- a/Common/Cpp/Sockets/Sockets_Tests.cpp +++ b/Common/Cpp/Sockets/Sockets_Tests.cpp @@ -161,23 +161,6 @@ struct ServerListener : AbstractServerSocket::Listener{ }; -// A server listener that tears the server down from within its own -// on_receive_data() callback via close() - the server-side counterpart of -// ClosingClientListener. close() must return promptly here: on POSIX and -// Windows the callback runs on the connection thread that the blocking -// close_and_wait() would join, and on Qt it runs on the event thread that -// close_and_wait() would block. -struct ClosingServerListener : ServerListener{ - std::atomic closed_in_callback{0}; - - virtual void on_receive_data(const void*, size_t) override{ - server->close(); - closed_in_callback++; - waiter.notify(); - } -}; - - // The parallel test runner can starve threads for long stretches on // loaded CI machines, where wall-clock assertions then fail tests that // would pass on a healthy machine. A small fixed workload (a 32 MB @@ -345,8 +328,6 @@ class Test_Sockets_Echo : public TestSockets error = "The server did not call on_disconnect"; } - server.close(); - if (!ok && !error.empty()){ return error; } @@ -424,8 +405,6 @@ class Test_Sockets_ZeroLengthSend : public TestSockets 0; } )){ - server.close(); return "The second server did not report its start"; } if (second_listener.last_listen_error.empty()){ - server.close(); - second_server.close(); return "The second server succeeded on a port that is already in use"; } if (second_server.state() != AbstractServerSocket::State::NOT_RUNNING){ - server.close(); - second_server.close(); return "The second server is not NOT_RUNNING after a failed start"; } @@ -928,9 +894,6 @@ class Test_Sockets_PortInUse : public TestSockets -class Test_Sockets_ServerCloseFromReceiveCallback : public TestSockets{ -public: - using TestSockets::TestSockets; - - virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{ - if (timing_unreliable()){ - return UnitTestResult( - UnitTestResult::SKIPPED, - "Machine too starved for a timing-sensitive socket test (timing_unreliable())." - ); - } - ClosingServerListener server_listener; - ServerSocketType server(this->m_thread_pool); - server.add_listener(server_listener); - server_listener.server = &server; - - uint16_t port; - if (!this->start_server(server, server_listener, port)){ - if (timing_unreliable()){ - return UnitTestResult( - UnitTestResult::SKIPPED, - "The server did not start listening on a starved machine." - ); - } - return "Failed to start the server"; - } - - bool ok = false; - std::string error; - { - ClientListener client_listener; - ClientSocketType client(this->m_thread_pool); - client.add_listener(client_listener); - - client.connect("127.0.0.1", port); - if (!client_listener.waiter.wait_for( - SOCKET_TEST_WAIT, - [&client_listener]{ return client_listener.connect_finished.load() >= 1; } - )){ - error = "The client did not finish connecting"; - }else if (!client_listener.last_connect_error.empty()){ - error = "The client failed to connect: " + client_listener.last_connect_error; - }else if (!server_listener.waiter.wait_for( - SOCKET_TEST_WAIT, - [&server_listener]{ return server_listener.connected.load() >= 1; } - )){ - error = "The server did not call on_connect"; - }else if (client.send("ping", 4) != 4){ - error = "The client did not send the trigger packet"; - }else if (!server_listener.waiter.wait_for( - SOCKET_TEST_WAIT, - [&server_listener]{ return server_listener.closed_in_callback.load() >= 1; } - )){ - error = "close() did not return from the on_receive_data() callback (it would have blocked, like close_and_wait() would)"; - }else if (server.state() == AbstractServerSocket::State::CONNECTED - || server.state() == AbstractServerSocket::State::LISTENING - ){ - error = "After close() the server is still connected or listening"; - }else{ - // close() (called in the callback) only requested the - // teardown. The blocking close_and_wait() runs when - // start() is called again below and when "server" is - // destroyed - neither may hang. - ok = true; - } - } - - // Re-listen on the same server: start() must complete the - // close() requested in the callback (its close_and_wait() - // prelude) and bind again. - if (ok && !this->start_server(server, server_listener, port)){ - if (timing_unreliable()){ - return UnitTestResult( - UnitTestResult::SKIPPED, - "The server did not re-start listening on a starved machine." - ); - } - error = "The server did not re-start listening after close()"; - } - - server.close(); - if (!ok && !error.empty()){ return error; } @@ -2554,9 +2402,6 @@ void add_socket_tests(UnitTestDatabase& database, ThreadPool& thread_pool, const database.add>( thread_pool, prefix + "close() from the receive callback" ); - database.add>( - thread_pool, prefix + "server close() from the receive callback" - ); }