Realm C++ SDK Version v2.2.0
|
#include <websocket.hpp>
Classes | |
struct | timer |
Public Types | |
using | FunctionHandler = std::function< void(status)> |
Function handler typedef. | |
using | sync_timer = std::unique_ptr< sync_socket_provider::timer > |
Other class typedefs. | |
Public Member Functions | |
virtual | ~sync_socket_provider ()=default |
virtual std::unique_ptr< websocket_interface > | connect (std::unique_ptr< websocket_observer > observer, websocket_endpoint &&endpoint)=0 |
virtual void | post (FunctionHandler &&handler)=0 |
virtual sync_timer | create_timer (std::chrono::milliseconds delay, FunctionHandler &&handler)=0 |
Sync Socket Provider interface that provides the event loop and WebSocket factory used by the SyncClient.
All callback and event operations in the SyncClient must be completed in the order in which they were issued (via post() or timer) to the event loop and cannot be run in parallel. It is up to the custom event loop implementation to determine if these are run on the same thread or a thread pool as long as it is guaranteed that the callback handler functions are processed in order and not run concurrently.
The implementation of a sync_socket_provider must support the following operations that post handler functions (via by the Sync client) onto the event loop:
The event loop is not required to be a single thread as long as the following requirements are satisfied:
The sync_socket_provider also provides a WebSocket interface for connecting to the server via a WebSocket connection.
|
virtualdefault |
The event loop implementation must ensure the event loop is stopped and flushed when the object is destroyed. If the event loop is processed by a thread, the thread must be joined as part of this operation.
|
pure virtual |
Create a new websocket pointed to the server indicated by endpoint and connect to the server. Any events that occur during the execution of the websocket will call directly to the handlers provided by the observer. The web_socket_observer guarantees that the WebSocket object will be closed/destroyed before the observer is terminated/destroyed.
Implemented in realm::networking::default_socket_provider.
|
pure virtual |
Create and register a new timer whose handler function will be posted to the event loop when the provided delay expires.
This is a one shot timer and the Timer class returned becomes invalid once the timer has expired. A new timer will need to be created to wait again.
delay | The duration to wait in ms before the timer expires. |
handler | The handler function to be called on the event loop when the timer expires. |
Implemented in realm::networking::default_socket_provider.
|
pure virtual |
Submit a handler function to be executed by the event loop (thread).
Register the specified handler function to be queued on the event loop for immediate asynchronous execution. The specified handler will be executed by an expression on the form handler()
. If the the handler object is movable, it will never be copied. Otherwise, it will be copied as necessary.
This function is thread-safe and can be called by any thread. It can also be called from other post() handler function.
The handler will never be called as part of the execution of post(). If post() is called on a thread separate from the event loop, the handler may be called before post() returns.
Handler functions added through post() must be executed in the order they are added. More precisely, if post() is called twice to add two handlers, A and B, and the execution of post(A) ends before the beginning of the execution of post(B), then A is guaranteed to execute before B.
handler | The handler function to be queued on the event loop. |
Implemented in realm::networking::default_socket_provider.