Skip to content

Sockets: make ServerSocket::close() private; the destructor performs the teardown - #1864

Merged
Mysticial merged 1 commit into
mainfrom
server-close-private
Nov 7, 2026
Merged

Mysticial merged 1 commit into
mainfrom
server-close-private

Conversation

@pa-devbot

Copy link
Copy Markdown
Collaborator

Follow-up to #1859 (per review of it): I don't think both close_connection() and close() need to be public. If a listener wants to disconnect the client, it can call close_connection(). Completely shutting down the server and blocking future connections only needs to happen in the destructor.

Changes

  • AbstractServerSocket no longer declares close(). Each backend now has a private non-virtual close() - the blocking teardown, bodies unchanged from main for POSIX/WinSocket, the QTcpServer-destroying body for Qt - called only by the destructor.
  • Removes the public non-blocking close() and the private close_and_wait() introduced by Sockets: make ServerSocket::close() private; the destructor performs the teardown #1859, plus the start() prelude: with close() no longer user-callable, a server can never be left DESTRUCTING while the object is alive.
  • close_connection() keeps its public API; its doc now contrasts with "the full teardown the destructor performs" instead of a public close().
  • Kept the Qt on_close_connection() DESTRUCTING-preservation from Sockets: make ServerSocket::close() private; the destructor performs the teardown #1859: a queued connection-close can still run on the event thread after the destructor's close() has set DESTRUCTING (it is queued before the destruction event), and without the check the state could flicker back to LISTENING mid-teardown and accept a connection.
  • Sockets_Tests.cpp: all server.close()/second_server.close() cleanup calls removed - the destructor now performs the same teardown at scope exit - and Sockets: make ServerSocket::close() private; the destructor performs the teardown #1859's server-callback regression test dropped (its public close() no longer exists).

Verification

Full local run: 0 failures, all 27 socket tests pass (Qt 15 + POSIX 12); POSIX/WinSocket .cpp files end up byte-identical to main.

…the teardown

Per review: only close_connection() needs to be public. A listener
that wants to disconnect the client calls close_connection(); completely
shutting down the server only needs to happen in the destructor.

- Remove close() from the public API of AbstractServerSocket and the
  backends. Each backend now has a private non-virtual close() (the
  blocking teardown, unchanged bodies for POSIX/WinSocket) that only the
  destructor calls.
- Remove close_and_wait() and the start() prelude: close() is no longer
  user-callable, so a server can never be left DESTRUCTING while alive.
- Keep the Qt DESTRUCTING-preservation in on_close_connection(): a
  queued connection-close can still race the destructor's close().
- Drop the server-callback regression test from the first commit and all
  server.close() cleanup calls in Sockets_Tests.cpp; the destructor now
  performs the teardown at scope exit.
@Mysticial
Mysticial merged commit 3cac16d into main Nov 7, 2026
8 checks passed
@Mysticial
Mysticial deleted the server-close-private branch November 7, 2026 22:53
Mysticial pushed a commit that referenced this pull request Nov 7, 2026
Mirrors the ClientSocket naming, per review of #1864: the private
blocking teardown in ServerSocket_POSIX, ServerSocket_WinSocket and
ServerSocket_Qt is now close_and_wait() (destructor-only), and the
comments and docs that referred to it as close() are updated. No
behaviour change.

Co-authored-by: PA Dev Bot <344001113+pa-devbot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants