Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. Comms
  5. pw_transfer
  6. pw::transfer::Client Class Reference
Loading...
Searching...
No Matches
pw::transfer::Client Class Reference

Overview

RPC client for running pw_transfer read and write data transfers.

Currently, a Client is capable of running transfers over a single RPC channel, processed on a shared TransferThread.

Classes

class  Handle
 

Public Types

using CompletionFunc = Function< void(Status)>
 

Public Member Functions

 Client (rpc::Client &rpc_client, uint32_t channel_id, TransferThread &transfer_thread, size_t max_window_size_bytes, uint32_t extend_window_divisor=cfg::kDefaultExtendWindowDivisor)
 
 Client (rpc::Client &rpc_client, uint32_t channel_id, TransferThread &transfer_thread)
 
 Client (const Client &)=delete
 
 Client (Client &&)=delete
 
Client & operator= (const Client &)=delete
 
Client & operator= (Client &&)=delete
 
Result< Handle > Read (uint32_t resource_id, stream::Writer &output, CompletionFunc &&on_completion, ProtocolVersion protocol_version, chrono::SystemClock::duration timeout=cfg::kDefaultClientTimeout, chrono::SystemClock::duration initial_chunk_timeout=cfg::kDefaultInitialChunkTimeout, uint32_t initial_offset=0u)
 
Result< Handle > Read (uint32_t resource_id, stream::Writer &output, CompletionFunc &&on_completion, chrono::SystemClock::duration timeout=cfg::kDefaultClientTimeout, chrono::SystemClock::duration initial_chunk_timeout=cfg::kDefaultInitialChunkTimeout, uint32_t initial_offset=0u)
 
Result< Handle > Write (uint32_t resource_id, stream::Reader &input, CompletionFunc &&on_completion, ProtocolVersion protocol_version, chrono::SystemClock::duration timeout=cfg::kDefaultClientTimeout, chrono::SystemClock::duration initial_chunk_timeout=cfg::kDefaultInitialChunkTimeout, uint32_t initial_offset=0u)
 
Result< Handle > Write (uint32_t resource_id, stream::Reader &input, CompletionFunc &&on_completion, chrono::SystemClock::duration timeout=cfg::kDefaultClientTimeout, chrono::SystemClock::duration initial_chunk_timeout=cfg::kDefaultInitialChunkTimeout, uint32_t initial_offset=0u)
 
Status set_extend_window_divisor (uint32_t extend_window_divisor)
 
constexpr Status set_max_retries (uint32_t max_retries)
 
constexpr Status set_max_lifetime_retries (uint32_t max_lifetime_retries)
 
constexpr void set_protocol_version (ProtocolVersion new_version)
 
bool has_read_stream () const
 
bool has_write_stream () const
 

Friends

class internal::TransferThread
 

Member Typedef Documentation

◆ CompletionFunc

Callback invoked from the transfer thread when a transfer completes, receiving the overall status of the transfer.

Constructor & Destructor Documentation

◆ Client() [1/2]

pw::transfer::Client::Client ( rpc::Client &  rpc_client,
uint32_t  channel_id,
TransferThread &  transfer_thread,
size_t  max_window_size_bytes,
uint32_t  extend_window_divisor = cfg::kDefaultExtendWindowDivisor 
)
inline

Initializes a transfer client on a specified RPC client and channel.

Transfer tasks are processed on the provided transfer_thread, which may be shared between a transfer client and service.

Parameters
[in]rpc_clientRPC client over which transfer streams are opened.
[in]channel_idRPC channel ID on which transfers are run.
[in]transfer_threadThread used to process transfer events.
[in]max_window_size_bytesMaximum amount of data in bytes to request at a time during a read transfer, unless told a more restrictive amount by the transfer's stream. This size should span multiple chunks and can be set quite large; the transfer protocol automatically adjusts its window size as a transfer progresses.
[in]extend_window_divisorFractional position within a window at which a receive transfer extends its window size.

◆ Client() [2/2]

pw::transfer::Client::Client ( rpc::Client &  rpc_client,
uint32_t  channel_id,
TransferThread &  transfer_thread 
)
inline
Deprecated:
Explicitly provide max_window_size_bytes instead.
Parameters
[in]rpc_clientRPC client over which transfer streams are opened.
[in]channel_idRPC channel ID on which transfers are run.
[in]transfer_threadThread used to process transfer events.

Member Function Documentation

◆ has_read_stream()

bool pw::transfer::Client::has_read_stream ( ) const
inline

Checks whether the client currently has an open RPC Read() stream.

Returns
true if a client read stream is open, false otherwise.

◆ has_write_stream()

bool pw::transfer::Client::has_write_stream ( ) const
inline

Checks whether the client currently has an open RPC Write() stream.

Returns
true if a client write stream is open, false otherwise.

◆ Read() [1/2]

Result< Handle > pw::transfer::Client::Read ( uint32_t  resource_id,
stream::Writer &  output,
CompletionFunc &&  on_completion,
chrono::SystemClock::duration  timeout = cfg::kDefaultClientTimeout,
chrono::SystemClock::duration  initial_chunk_timeout = cfg::kDefaultInitialChunkTimeout,
uint32_t  initial_offset = 0u 
)
inline

Begins a new read transfer for the given resource_id using the client's configured default protocol version.

Data read from the server is written to output. Due to the asynchronous nature of transfer operations, this function only returns an error status synchronously if called with invalid arguments; transfer errors during execution are reported through on_completion on the transfer thread.

Parameters
[in]resource_idID of the server resource to read.
[in,out]outputStream to which received data is written.
[in]on_completionCallback invoked from the transfer thread with the overall transfer status when the transfer finishes.
[in]timeoutMaximum time to wait for a chunk before retrying.
[in]initial_chunk_timeoutMaximum time to wait for the server's initial response chunk before retrying.
[in]initial_offsetStarting byte offset within the server resource.
Returns
A Result containing a Handle to manage the active transfer on success or one of the following error codes on failure:

◆ Read() [2/2]

Result< Handle > pw::transfer::Client::Read ( uint32_t  resource_id,
stream::Writer &  output,
CompletionFunc &&  on_completion,
ProtocolVersion  protocol_version,
chrono::SystemClock::duration  timeout = cfg::kDefaultClientTimeout,
chrono::SystemClock::duration  initial_chunk_timeout = cfg::kDefaultInitialChunkTimeout,
uint32_t  initial_offset = 0u 
)

Begins a new read transfer for the given resource_id using an explicit protocol_version.

Data read from the server is written to output. Due to the asynchronous nature of transfer operations, this function only returns an error status synchronously if called with invalid arguments; transfer errors during execution are reported through on_completion on the transfer thread.

When initial_offset is non-zero, output is used as-is without seeking; the caller must position output beforehand if needed.

Parameters
[in]resource_idID of the server resource to read.
[in,out]outputStream to which received data is written.
[in]on_completionCallback invoked from the transfer thread with the overall transfer status when the transfer finishes.
[in]protocol_versionProtocol version to request for this transfer.
[in]timeoutMaximum time to wait for a chunk before retrying.
[in]initial_chunk_timeoutMaximum time to wait for the server's initial response chunk before retrying.
[in]initial_offsetStarting byte offset within the server resource.
Returns
A Result containing a Handle to manage the active transfer on success or one of the following error codes on failure:

◆ set_extend_window_divisor()

Status pw::transfer::Client::set_extend_window_divisor ( uint32_t  extend_window_divisor)
inline

Sets the window divisor at which receive transfers extend their window.

Parameters
[in]extend_window_divisorFractional divisor (must be greater than 1).
Returns

◆ set_max_lifetime_retries()

constexpr Status pw::transfer::Client::set_max_lifetime_retries ( uint32_t  max_lifetime_retries)
inlineconstexpr

Sets the maximum total retries allowed over the lifetime of a transfer.

Parameters
[in]max_lifetime_retriesMaximum lifetime retries (must be greater than or equal to max_retries).
Returns
  • OK: max_lifetime_retries was updated.
  • INVALID_ARGUMENT: max_lifetime_retries is less than max_retries.

◆ set_max_retries()

constexpr Status pw::transfer::Client::set_max_retries ( uint32_t  max_retries)
inlineconstexpr

Sets the maximum number of retries for an individual chunk on new transfers.

Parameters
[in]max_retriesRetry count (must be between 1 and the smaller of max_lifetime_retries and 255).
Returns
  • OK: max_retries was updated.
  • INVALID_ARGUMENT: max_retries is 0, exceeds max_lifetime_retries, or exceeds std::numeric_limits<uint8_t>::max().

◆ set_protocol_version()

constexpr void pw::transfer::Client::set_protocol_version ( ProtocolVersion  new_version)
inlineconstexpr

Sets the default protocol version requested when starting new transfers.

Parameters
[in]new_versionProtocol version to request by default.

◆ Write() [1/2]

Result< Handle > pw::transfer::Client::Write ( uint32_t  resource_id,
stream::Reader &  input,
CompletionFunc &&  on_completion,
chrono::SystemClock::duration  timeout = cfg::kDefaultClientTimeout,
chrono::SystemClock::duration  initial_chunk_timeout = cfg::kDefaultInitialChunkTimeout,
uint32_t  initial_offset = 0u 
)
inline

Begins a new write transfer for the given resource_id using the client's configured default protocol version.

Data from input is sent to the server. Due to the asynchronous nature of transfer operations, this function only returns an error status synchronously if called with invalid arguments; transfer errors during execution are reported through on_completion on the transfer thread.

Parameters
[in]resource_idID of the server resource to write.
[in,out]inputStream from which data to transmit is read.
[in]on_completionCallback invoked from the transfer thread with the overall transfer status when the transfer finishes.
[in]timeoutMaximum time to wait for a chunk before retrying.
[in]initial_chunk_timeoutMaximum time to wait for the server's initial response chunk before retrying.
[in]initial_offsetStarting byte offset within the server resource.
Returns
A Result containing a Handle to manage the active transfer on success or one of the following error codes on failure:

◆ Write() [2/2]

Result< Handle > pw::transfer::Client::Write ( uint32_t  resource_id,
stream::Reader &  input,
CompletionFunc &&  on_completion,
ProtocolVersion  protocol_version,
chrono::SystemClock::duration  timeout = cfg::kDefaultClientTimeout,
chrono::SystemClock::duration  initial_chunk_timeout = cfg::kDefaultInitialChunkTimeout,
uint32_t  initial_offset = 0u 
)

Begins a new write transfer for the given resource_id using an explicit protocol_version.

Data from input is sent to the server. Due to the asynchronous nature of transfer operations, this function only returns an error status synchronously if called with invalid arguments; transfer errors during execution are reported through on_completion on the transfer thread.

When initial_offset is non-zero, input is used as-is without seeking; the caller must position input beforehand if needed.

Parameters
[in]resource_idID of the server resource to write.
[in,out]inputStream from which data to transmit is read.
[in]on_completionCallback invoked from the transfer thread with the overall transfer status when the transfer finishes.
[in]protocol_versionProtocol version to request for this transfer.
[in]timeoutMaximum time to wait for a chunk before retrying.
[in]initial_chunk_timeoutMaximum time to wait for the server's initial response chunk before retrying.
[in]initial_offsetStarting byte offset within the server resource.
Returns
A Result containing a Handle to manage the active transfer on success or one of the following error codes on failure:

The documentation for this class was generated from the following file: