RPC service for running server-side pw_transfer transfers.
Register Handler instances with RegisterHandler() for each transferable resource, and register the TransferService with a pw::rpc::Server.
|
|
using | StartCallback = pw::Function< void(uint32_t session_id, uint32_t resource_id)> |
| | Callback invoked from the transfer thread when a server transfer starts.
|
| |
|
using | EndCallback = pw::Function< void(uint32_t session_id, Status status)> |
| | Callback invoked from the transfer thread when a server transfer ends.
|
| |
◆ TransferService() [1/2]
| pw::transfer::TransferService::TransferService |
( |
TransferThread & |
transfer_thread, |
|
|
uint32_t |
max_window_size_bytes, |
|
|
chrono::SystemClock::duration |
chunk_timeout = cfg::kDefaultServerTimeout, |
|
|
uint8_t |
max_retries = cfg::kDefaultMaxServerRetries, |
|
|
uint32_t |
extend_window_divisor = cfg::kDefaultExtendWindowDivisor, |
|
|
uint32_t |
max_lifetime_retries = cfg::kDefaultMaxLifetimeRetries |
|
) |
| |
|
inline |
Initializes a TransferService that can be registered with an RPC server.
The transfer service runs all transfer tasks on transfer_thread, which may be shared between a TransferService and a Client.
- Parameters
-
| [in] | transfer_thread | Thread on which transfer events are processed. |
| [in] | max_window_size_bytes | Maximum amount of data in bytes to request at a time during a write transfer, unless further restricted by a handler's stream. Should span multiple chunks; the protocol automatically adjusts its window size as a transfer progresses. |
| [in] | chunk_timeout | Maximum time to wait for a chunk before retrying or timing out. |
| [in] | max_retries | Maximum retries for a single chunk before aborting. |
| [in] | extend_window_divisor | Fractional window position at which a receive transfer extends its window size. |
| [in] | max_lifetime_retries | Maximum total retries allowed across the lifetime of a transfer. |
◆ TransferService() [2/2]
Initializes a TransferService with server transfer lifecycle callbacks.
- Parameters
-
| [in] | transfer_thread | Thread on which transfer events are processed. |
| [in] | max_window_size_bytes | Maximum amount of data in bytes to request at a time during a write transfer. |
| [in] | on_start | Callback invoked when a server transfer begins. |
| [in] | on_end | Callback invoked when a server transfer completes. |
- Warning
- The
on_start and on_end callbacks are invoked from the transfer thread, so the implementation of the callbacks:
- Must not attempt to interact with the transfer thread, as doing so can cause deadlock or internal state corruption.
- Must return quickly to avoid stalling the transfer thread or the RPC thread.
◆ GetResourceStatus()
| void pw::transfer::TransferService::GetResourceStatus |
( |
ConstByteSpan |
request, |
|
|
rpc::RawUnaryResponder & |
responder |
|
) |
| |
RPC handler for GetResourceStatus unary requests.
- Parameters
-
| [in] | request | Serialized ResourceStatusRequest protobuf payload. |
| [in] | responder | Raw unary responder used to send the status response. |
◆ Read()
| void pw::transfer::TransferService::Read |
( |
RawServerReaderWriter & |
reader_writer | ) |
|
|
inline |
RPC handler for bidirectional server read transfers.
- Parameters
-
| [in] | reader_writer | Active raw RPC bidirectional stream. |
◆ RegisterHandler()
| bool pw::transfer::TransferService::RegisterHandler |
( |
Handler & |
handler | ) |
|
|
inline |
Registers a Handler for a transferable resource with the service.
Blocks until the registration event is processed by the transfer thread.
- Parameters
-
| [in] | handler | Resource handler to register. Must remain valid until unregistered. |
- Returns
true if the handler was registered, false if queuing the event on the transfer thread timed out.
◆ set_chunk_timeout()
Sets the chunk timeout for server transfers.
- Parameters
-
| [in] | chunk_timeout | Duration to wait for a chunk before retrying or aborting. |
◆ set_extend_window_divisor()
| constexpr Status pw::transfer::TransferService::set_extend_window_divisor |
( |
uint32_t |
extend_window_divisor | ) |
|
|
inlineconstexpr |
Sets the window divisor at which receive transfers extend their window.
- Parameters
-
| [in] | extend_window_divisor | Fractional divisor (must be greater than 1). |
- Returns
-
◆ set_max_chunk_size_bytes()
| constexpr void pw::transfer::TransferService::set_max_chunk_size_bytes |
( |
uint32_t |
max_chunk_size_bytes | ) |
|
|
inlineconstexpr |
Sets the maximum size for the data payload in a pw_transfer chunk.
Note that the max chunk size must always fit within the transfer thread's chunk buffer.
- Parameters
-
| [in] | max_chunk_size_bytes | Maximum chunk payload size in bytes. |
◆ set_max_pending_bytes()
| constexpr void pw::transfer::TransferService::set_max_pending_bytes |
( |
uint32_t |
pending_bytes | ) |
|
|
inlineconstexpr |
◆ set_max_retries()
| constexpr void pw::transfer::TransferService::set_max_retries |
( |
uint8_t |
max_retries | ) |
|
|
inlineconstexpr |
Sets the maximum number of retries per chunk on the server.
- Parameters
-
| [in] | max_retries | Maximum retries per chunk. |
◆ set_max_window_size_bytes()
| constexpr void pw::transfer::TransferService::set_max_window_size_bytes |
( |
uint32_t |
max_window_size_bytes | ) |
|
|
inlineconstexpr |
Sets the maximum receive window size in bytes for write transfers.
- Parameters
-
| [in] | max_window_size_bytes | Maximum receive window size in bytes. |
◆ UnregisterHandler()
| bool pw::transfer::TransferService::UnregisterHandler |
( |
Handler & |
handler | ) |
|
|
inline |
Unregisters a previously registered Handler from the service.
Blocks until the handler is fully cleaned up on the transfer thread.
- Parameters
-
| [in] | handler | Resource handler to unregister. |
- Returns
true if the handler was unregistered, false if queuing the event on the transfer thread timed out.
◆ Write()
| void pw::transfer::TransferService::Write |
( |
RawServerReaderWriter & |
reader_writer | ) |
|
|
inline |
RPC handler for bidirectional server write transfers.
- Parameters
-
| [in] | reader_writer | Active raw RPC bidirectional stream. |
The documentation for this class was generated from the following file:
- pw_transfer/public/pw_transfer/transfer.h