|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
Raw-socket WebSocket server front for morph::backend::RemoteServer. More...
#include <socket_server.hpp>
Public Types | |
| using | Config = SocketServerConfig |
| Alias for the config struct. | |
Public Member Functions | |
| SocketServer (::morph::exec::IoLoop &loop, ::morph::backend::RemoteServer &server, std::uint16_t port, Config cfg={}) | |
Constructs the server on loop; does not start listening. | |
| SocketServer (::morph::backend::RemoteServer &server, std::uint16_t port, Config cfg={}) | |
| Constructs the server on a loop of its own, created by the first listen(); does not start listening. | |
| SocketServer (const SocketServer &)=delete | |
| SocketServer & | operator= (const SocketServer &)=delete |
| SocketServer (SocketServer &&)=delete | |
| SocketServer & | operator= (SocketServer &&)=delete |
| ~SocketServer () | |
| Stops accepting and closes every client connection. | |
| bool | listen () |
| Starts listening for incoming WebSocket connections. | |
| std::uint16_t | port () const |
| Returns the port the server is currently bound to. | |
| void | close () |
| Stops accepting new connections and closes every client connection. | |
Raw-socket WebSocket server front for morph::backend::RemoteServer.
Mirrors morph::qt::QtWebSocketServer's behavior without Qt: for each accepted connection it performs the RFC 6455 handshake, then reads framed text messages and forwards each to RemoteServer::handle(); the reply is written back to the originating socket, or dropped if the connection is gone by the time the reply is ready.
Cross-thread surface: listen() and close(), which run on the loop and wait for it (inline when already there), and port(), an atomic read.
Definition at line 106 of file socket_server.hpp.
Alias for the config struct.
Definition at line 109 of file socket_server.hpp.
|
inline |
Constructs the server on loop; does not start listening.
| loop | The application's I/O loop. Borrowed: it must outlive this server. |
| server | RemoteServer instance that processes incoming messages. Borrowed, not owned: it must outlive this server (see docs/spec/concurrency_and_lifetimes.md, "Destruction ordering"). |
| port | TCP port to listen on. Pass 0 to let the OS pick a free port. |
| cfg | Backlog and timeout tuning. Default: 64-connection backlog, 10s handshake timeout, 30s send timeout. |
Definition at line 121 of file socket_server.hpp.
|
inline |
Constructs the server on a loop of its own, created by the first listen(); does not start listening.
| server | RemoteServer instance that processes incoming messages. Borrowed, not owned: it must outlive this server. |
| port | TCP port to listen on. Pass 0 to let the OS pick a free port. |
| cfg | Backlog and timeout tuning. |
Definition at line 131 of file socket_server.hpp.
|
inline |
Stops accepting and closes every client connection.
Closes on the loop and waits for it (inline when already there), then cuts the loop's tie to RemoteServer, so a connection's flow that resumes later touches neither this object nor the server.
Definition at line 145 of file socket_server.hpp.
|
inline |
Starts listening for incoming WebSocket connections.
Binds 127.0.0.1:port and starts the accept flow, on the loop. With no loop of its own yet, creates one first; a process out of descriptors cannot, and gets false.
Definition at line 160 of file socket_server.hpp.
|
inlinenodiscard |
Returns the port the server is currently bound to.
Definition at line 178 of file socket_server.hpp.
|
inline |
Stops accepting new connections and closes every client connection.
Releases the listening socket, so port() reads 0 afterwards and the bound port is free to rebind — the same post-close observation QtWebSocketServer makes. Reclaims every connection's models (RemoteServer::closeConnection) before it returns.
Runs on the loop and waits for it, inline when already there. Idempotent, and safe to call from several threads at once on a live object: each call is one loop task, and the loop runs them one at a time. Racing a call against the destructor is still the caller's problem (see docs/spec/concurrency_and_lifetimes.md, "Destruction ordering").
Definition at line 193 of file socket_server.hpp.