Repository navigation
Sockets: add AbstractServerSocket - #1785
Merged
Merged
Conversation
Abstract class for a minimal TCP server, mirroring the shape of AbstractClientSocket: - One connection at a time. Implementations use one worker thread for the accept loop and one thread-pool thread per active connection; a second incoming connection while one is active is rejected. - State machine: NOT_RUNNING -> LISTENING -> CONNECTED -> LISTENING, with DESTRUCTING while close() is in flight. - Listener hooks: on_thread_start, on_listen_finished (result of start()), on_connect, on_connect_rejected, on_receive_data, and on_disconnect (same semantics as AbstractClientSocket::Listener:: on_disconnect - not fired by close()). - start(address, port) reports its result through the listener, the same way connect() does for the client. - close_connection() drops the active client and keeps listening; close() is the full teardown and is idempotent.
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.
Abstract class only - no backends yet (Qt/POSIX/WinSocket to follow).
Mirrors the shape of
AbstractClientSocket:on_connect_rejected).NOT_RUNNING->LISTENING->CONNECTED->LISTENING, withDESTRUCTINGwhileclose()is in flight.on_thread_start,on_listen_finished(error_message)(the result ofstart(), likeon_connect_finishedfor the client),on_connect,on_connect_rejected,on_receive_data,on_disconnect(error_message)(same semantics as the client's - not fired byclose()/close_connection()).start(address, port)(async, result via listener),close_connection()(drop the client, keep listening),close()(full teardown, idempotent),send()(to the active connection, 0 if none).Design notes:
dispatch(notdispatch_now_blocking) - an earlier task blocking on a later task can deadlock the pool (see the note inThreadPool.h).close()/close_connection()must not be called from within a listener callback (same contract asClientSocket).on_connect, andget_port()for bind-port-0.