|
CIRCT 24.0.0git
|
A client for the cosim RPC server. More...
#include <RpcClient.h>

Classes | |
| struct | ChannelDesc |
| Description of a channel from the server. More... | |
| class | WriteChannelConnection |
| Handle for a sender registered with connectServerSender(). More... | |
| class | ReadChannelConnection |
| Abstract handle for a read channel connection. More... | |
Public Types | |
| enum class | ChannelDirection { ToServer , ToClient } |
| Channel direction as reported by the server. More... | |
| using | SendFetchCallback |
| Data source for a server-bound channel (see connectServerSender()): returns the frames of the next message to send (which may be none, e.g. | |
| using | SendErrorCallback = std::function<void(std::exception_ptr)> |
| Called with an exception thrown by a SendFetchCallback or while sending, e.g. | |
| using | ReadCallback |
| Callback type for receiving messages from a client-bound channel. | |
Public Member Functions | |
| RpcClient (Logger &logger, const std::string &hostname, uint16_t port) | |
| RpcClient (const RpcClient &)=delete | |
| ~RpcClient () | |
| RpcClient & | operator= (const RpcClient &)=delete |
| uint32_t | getEsiVersion () const |
| Get the ESI version from the manifest. | |
| std::vector< uint8_t > | getCompressedManifest () const |
| Get the compressed manifest from the server. | |
| bool | getChannelDesc (const std::string &channelName, ChannelDesc &desc) const |
| Get the channel description for a channel name. | |
| std::vector< ChannelDesc > | listChannels () const |
| List all channels available on the server. | |
| void | writeToServer (const std::string &channelName, const MessageData &data) |
| Send a message to a server-bound channel. | |
| bool | tryWriteToServer (const std::string &channelName, const std::vector< MessageData > &frames, bool force=false) |
| Non-blocking send of one message, split into frames, to a server-bound channel. | |
| void | setToServerMaxInFlight (const std::string &channelName, unsigned maxInFlight) |
| Set the maximum number of unconsumed frames on a server-bound channel. | |
| std::unique_ptr< WriteChannelConnection > | connectServerSender (const std::string &channelName, SendFetchCallback fetch, SendErrorCallback onError) |
| Send to a server-bound channel in callback (pull) mode, like WriteChannelPort's callback mode. | |
| std::unique_ptr< ReadChannelConnection > | connectClientReceiver (const std::string &channelName, ReadCallback callback, unsigned maxInFlight=DefaultToClientMaxInFlight) |
| Connect to a client-bound channel and receive messages via callback. | |
Static Public Attributes | |
| static constexpr unsigned | DefaultToServerMaxInFlight = 16 |
| Default maximum number of frames sent to a server-bound channel which the simulation has not yet consumed. | |
| static constexpr unsigned | DefaultToClientMaxInFlight = 32 |
| Default maximum number of frames in flight (queued in the simulator or sent but not yet consumed by the client) on a client-bound channel. | |
| static constexpr size_t | MaxSendsPerTurn = 64 |
| The most messages a sender sends before other channels are serviced. | |
Private Attributes | |
| std::unique_ptr< Impl > | impl |
A client for the cosim RPC server.
Hides the WebSocket + JSON transport behind a small C++ API; see cosim-protocol.md for the wire format.
Definition at line 36 of file RpcClient.h.
Callback type for receiving messages from a client-bound channel.
Return true if the message was consumed, false to retry the same owning message object.
Definition at line 136 of file RpcClient.h.
| using esi::backends::cosim::RpcClient::SendErrorCallback = std::function<void(std::exception_ptr)> |
Called with an exception thrown by a SendFetchCallback or while sending, e.g.
since the connection was lost.
Definition at line 105 of file RpcClient.h.
Data source for a server-bound channel (see connectServerSender()): returns the frames of the next message to send (which may be none, e.g.
for an empty message), or nullopt if no message is available yet. After returning nullopt (or throwing), it isn't called again until WriteChannelConnection::notify().
Definition at line 101 of file RpcClient.h.
|
strong |
Channel direction as reported by the server.
| Enumerator | |
|---|---|
| ToServer | |
| ToClient | |
Definition at line 52 of file RpcClient.h.
| RpcClient::RpcClient | ( | Logger & | logger, |
| const std::string & | hostname, | ||
| uint16_t | port ) |
Definition at line 1125 of file RpcClient.cpp.
|
delete |
|
default |
| std::unique_ptr< RpcClient::ReadChannelConnection > RpcClient::connectClientReceiver | ( | const std::string & | channelName, |
| ReadCallback | callback, | ||
| unsigned | maxInFlight = DefaultToClientMaxInFlight ) |
Connect to a client-bound channel and receive messages via callback.
maxInFlight is the maximum number of frames the simulator may have in flight for this channel; zero means unbounded. A frame stops counting once callback returns true for it. Returns a handle that disconnects when destroyed.
Definition at line 1170 of file RpcClient.cpp.
| std::unique_ptr< RpcClient::WriteChannelConnection > RpcClient::connectServerSender | ( | const std::string & | channelName, |
| SendFetchCallback | fetch, | ||
| SendErrorCallback | onError ) |
Send to a server-bound channel in callback (pull) mode, like WriteChannelPort's callback mode.
Whenever the channel is below its in-flight limit and fetch may have data, the client's transport thread calls fetch and sends all of the message's frames. Errors are reported to onError; exceptions it throws are logged. The callbacks are never called concurrently with each other. A channel can have only one sender, and nothing else should write to it meanwhile.
Definition at line 1162 of file RpcClient.cpp.
| bool RpcClient::getChannelDesc | ( | const std::string & | channelName, |
| ChannelDesc & | desc ) const |
Get the channel description for a channel name.
Returns true if the channel was found.
Definition at line 1136 of file RpcClient.cpp.
| std::vector< uint8_t > RpcClient::getCompressedManifest | ( | ) | const |
Get the compressed manifest from the server.
Definition at line 1132 of file RpcClient.cpp.
| uint32_t RpcClient::getEsiVersion | ( | ) | const |
Get the ESI version from the manifest.
Definition at line 1130 of file RpcClient.cpp.
| std::vector< RpcClient::ChannelDesc > RpcClient::listChannels | ( | ) | const |
List all channels available on the server.
Definition at line 1141 of file RpcClient.cpp.
| void RpcClient::setToServerMaxInFlight | ( | const std::string & | channelName, |
| unsigned | maxInFlight ) |
Set the maximum number of unconsumed frames on a server-bound channel.
Zero means unbounded.
Definition at line 1156 of file RpcClient.cpp.
| bool RpcClient::tryWriteToServer | ( | const std::string & | channelName, |
| const std::vector< MessageData > & | frames, | ||
| bool | force = false ) |
Non-blocking send of one message, split into frames, to a server-bound channel.
If the channel is below its in-flight limit, sends all of them (possibly overshooting the limit by frames.size() - 1) and returns true. Otherwise sends nothing and returns false. With force, sends regardless of the limit (but still counts the frames as in flight); for the rest of a message whose first part was admitted.
Definition at line 1150 of file RpcClient.cpp.
| void RpcClient::writeToServer | ( | const std::string & | channelName, |
| const MessageData & | data ) |
Send a message to a server-bound channel.
Blocks while the channel's in-flight limit is reached. Throws if the connection is lost. Frames sent before the simulation has connected its end of the channel are held by the server (and count as in flight), not dropped.
Definition at line 1145 of file RpcClient.cpp.
|
staticconstexpr |
Default maximum number of frames in flight (queued in the simulator or sent but not yet consumed by the client) on a client-bound channel.
Definition at line 73 of file RpcClient.h.
|
staticconstexpr |
Default maximum number of frames sent to a server-bound channel which the simulation has not yet consumed.
Definition at line 70 of file RpcClient.h.
|
private |
Definition at line 160 of file RpcClient.h.
|
staticconstexpr |
The most messages a sender sends before other channels are serviced.
Definition at line 120 of file RpcClient.h.