Repository navigation
Sockets: add the POSIX ServerSocket - #1793
Merged
Merged
Conversation
pa-devbot
force-pushed
the
sockets-server-posix
branch
from
November 1, 2026 01:42
cda953d to
2b873c2
Compare
pa-devbot
force-pushed
the
sockets-server-loopback
branch
from
November 1, 2026 02:44
82d5b0f to
544b9fb
Compare
pa-devbot
force-pushed
the
sockets-server-posix
branch
2 times, most recently
from
November 1, 2026 03:23
b4e7522 to
e7cd420
Compare
pa-devbot
force-pushed
the
sockets-server-loopback
branch
from
November 1, 2026 04:53
544b9fb to
20140b7
Compare
pa-devbot
force-pushed
the
sockets-server-posix
branch
from
November 1, 2026 04:59
e7cd420 to
77e2f4f
Compare
pa-devbot
force-pushed
the
sockets-server-posix
branch
2 times, most recently
from
November 1, 2026 09:17
427b871 to
ca15f0a
Compare
pa-devbot
force-pushed
the
sockets-server-posix
branch
from
November 1, 2026 09:57
ca15f0a to
c3a6503
Compare
pa-devbot
force-pushed
the
sockets-server-posix
branch
from
November 1, 2026 11:34
1eee4a5 to
d5c7b98
Compare
Mysticial
force-pushed
the
sockets-server-posix
branch
from
November 1, 2026 20:33
5c404ce to
a27eda4
Compare
Implements ServerSocket_POSIX (an accept-loop thread plus one connection thread at a time, both from the given thread pool via plain dispatch(), with non-blocking sockets; the implementation lives in ServerSocket_POSIX.cpp, following the split of the client backends) and enables the POSIX instantiation of the loopback tests on non-Windows. close()/close_connection() only flip the state: the connection thread notices within ~1 ms and closes the socket itself, so close_connection() is safe to call from within a listener callback. The accept loop keeps running while a connection is active and rejects new clients via on_connect_rejected. The connection task is started and published without holding the main lock: assigning to the task slot destroys the previous connection task's AsyncTask, whose destructor waits for that task to finish - and the task may be blocked on the main lock.
send() with MSG_DONTWAIT can return after writing only part of the buffer when the kernel's send buffer is full. macOS does this much more readily than Linux, so the 1 MiB loopback transfer test failed on the Mac CI: client.send() returned early with fewer bytes. Loop until the whole buffer has been written, matching the Qt backend's send() behavior.
The method bodies kept their in-class 8-space indentation from the monolithic header; un-dedent them to file scope.
The header/.cpp split left 2-3 blank lines between most members; normalize to the single-blank style used by the client headers.
Same issue as the WinSocket backend (#1820): the connection thread called ::recv() inside the m_lock scope. The socket is non-blocking so it returns immediately in practice, but a socket call must not stretch the lock across a kernel transition: if the socket were ever made blocking, every other caller of m_lock (close(), close_connection(), send(), the accept loop) would hang while the client stays silent. The loop now takes m_lock only for the state check, calls recv() unlocked, and re-checks under the lock that the connection has not been replaced before dispatching on_receive_data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on the PR for the Qt ServerSocket + test harness (merge that one first, then rebase this onto main).
Adds
ServerSocket_POSIX(an accept-loop thread plus one connectionthread at a time, both from the given thread pool via plain
dispatch(), non-blocking sockets) and enables the POSIX instantiationof the loopback tests on non-Windows.
Design
close()/close_connection()only flip the state; the connectionthread notices within ~1 ms and closes the socket itself, so
close_connection()is safe to call from within a listener callback.rejects new clients via
on_connect_rejected(one connection at atime).
main lock: assigning to the task slot destroys the previous
connection task's
AsyncTask, whose destructor waits for that taskto finish - and the task may be blocked on the main lock. Holding the
lock across the assignment deadlocks (found while testing).
Tests: the 7 loopback scenarios (echo, zero-length send, 1 MiB
transfer, rapid reconnects, send/close race, reject second client,
port in use) now run against the POSIX backend on non-Windows in
addition to Qt. Verified: 14/14 socket tests pass on Linux, plus a
standalone POSIX harness (39 checks) and repeated stress runs.
Note (rebuild on current main): the implementation now lives in
ServerSocket_POSIX.cpp, mirroring the client header/.cpp split (#1795). Also fixes an implicitsize_t->intnarrowing in the send loop that-Wshorten-64-to-32rejected on the Mac CIs.Update (Mac CI): the 1 MiB "Large transfer" test failed on both Mac
CIs with "The client did not send all 1048576 bytes": macOS
send()with
MSG_DONTWAITreadily returns after a partial write when thekernel's send buffer is full (Linux usually does not), and
ClientSocket_POSIX::send()returned early on a partial send. It nowloops until the whole buffer is written, matching the Qt backend.
Verified with the standalone POSIX harness.
Update (formatting): fixed
ServerSocket_POSIX.cppindentationleft over from the header/.cpp split (method bodies had kept their
in-class 8-space indent). The
Mutex/ConditionVariablewrappermigration from #1787 comes in with the rebase.