Owns a heap-allocated RPC call object, such as a RawServerReaderWriter or PwpbClientReader.
Destroying a call object waits for its running callbacks to finish, which deadlocks if a callback destroys its own call, or if a thread destroys a call while holding a lock that the call's running callback is waiting for. Resetting or destroying a DynamicCallPtr closes the call immediately instead. If one of the call's callbacks is running, the call object is deleted when that callback finishes rather than waiting for it.
Closing the call works as when a call object is destroyed: server calls are completed with an OK status and client calls are abandoned. Unlike destroying a call object, a pending on_error from an earlier abort or cancellation is discarded and not invoked.
A DynamicCallPtr is not thread safe. Synchronize access to a DynamicCallPtr that is used from multiple threads. To avoid destroying callbacks while holding a lock, move the DynamicCallPtr out of the lock's scope before destroying it.
Requires PW_RPC_DYNAMIC_ALLOCATION.
| CallType | The RPC call object type. |
| UniquePtr | The owning smart pointer for the call object. Defaults to the type returned by PW_RPC_MAKE_UNIQUE_PTR. Other smart pointers, such as a std::unique_ptr with a custom deleter, may be used if they are no larger than that type. |
Public Member Functions | |
| constexpr | DynamicCallPtr ()=default |
Creates an empty DynamicCallPtr. | |
| constexpr | DynamicCallPtr (std::nullptr_t) |
| DynamicCallPtr (UniquePtr ptr) | |
| Takes ownership of a heap-allocated call object. | |
| DynamicCallPtr (const DynamicCallPtr &)=delete | |
| DynamicCallPtr & | operator= (const DynamicCallPtr &)=delete |
| DynamicCallPtr (DynamicCallPtr &&other) noexcept | |
| DynamicCallPtr & | operator= (DynamicCallPtr &&other) noexcept |
| DynamicCallPtr & | operator= (std::nullptr_t) noexcept |
| void | reset () noexcept |
| CallType * | get () const noexcept |
| CallType & | operator* () const noexcept |
| CallType * | operator-> () const noexcept |
| operator bool () const noexcept | |
Friends | |
| bool | operator== (const DynamicCallPtr &lhs, std::nullptr_t) noexcept |
| bool | operator== (std::nullptr_t, const DynamicCallPtr &rhs) noexcept |
| bool | operator!= (const DynamicCallPtr &lhs, std::nullptr_t) noexcept |
| bool | operator!= (std::nullptr_t, const DynamicCallPtr &rhs) noexcept |