class AsyncBinding
Defined at line 90 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/async_binding.h
|AsyncBinding| objects implement the common logic for registering waits
on channels, and teardown. |AsyncBinding| itself composes |async_wait_t|
which borrows the channel to wait for messages. The actual responsibilities
of managing channel ownership falls on the various subclasses, which must
ensure the channel is not destroyed while there are outstanding waits.
|AsyncBinding| objects are always managed by a |std::shared_ptr|. Messaging
APIs typically promote a corresponding |std::weak_ptr| briefly when they need
to write to the transport, and gracefully report an *unbound* error if the
binding has been destroyed.
Public Methods
void ~AsyncBinding ()
Defined at line 92 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/async_binding.h
void BeginFirstWait ()
Defined at line 123 of file ../../sdk/lib/fidl/cpp/wire/async_binding.cc
TeardownTaskPostingResult StartTeardown (std::shared_ptr<AsyncBinding> && calling_ref)
Defined at line 143 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/async_binding.h
std::shared_ptr<LockedUnbindInfo> shared_unbind_info ()
Gets a reference to the shared unbind info. It is only safe to get the
|UnbindInfo| after the binding object is destroyed.
Defined at line 170 of file ../../sdk/lib/fidl/cpp/wire/async_binding.cc
zx_status_t CheckForTeardownAndBeginNextWait ()
Checks for the need to teardown and registers the next wait in one critical
section:
- If we are already in |Lifecycle::MustTeardown|, early return an error.
- Otherwise, adds the next wait to the dispatcher, recording any error in
|lifecycle_|.
When used from the message handler, the message handler should immediately
perform teardown when this method returns an error.
Defined at line 174 of file ../../sdk/lib/fidl/cpp/wire/async_binding.cc
void HandleError (std::shared_ptr<AsyncBinding> && calling_ref, DispatchError error)
Notifies the binding of an |error| while servicing messages.
This may lead to binding teardown.
Defined at line 194 of file ../../sdk/lib/fidl/cpp/wire/async_binding.cc
bool IsDestructionImminent ()
Returns true if the binding will teardown at the next iteration of the
event loop, or has already torn down and pending deletion.
Defined at line 200 of file ../../sdk/lib/fidl/cpp/wire/async_binding.cc
Protected Methods
void AsyncBinding (async_dispatcher_t * dispatcher, internal::AnyUnownedTransport transport, ThreadingPolicy threading_policy)
Defined at line 61 of file ../../sdk/lib/fidl/cpp/wire/async_binding.cc
void MessageHandler (fidl::IncomingHeaderAndMessage & msg, internal::MessageStorageViewBase * storage_view)
Common message handling entrypoint shared by both client and server bindings.
Defined at line 78 of file ../../sdk/lib/fidl/cpp/wire/async_binding.cc
void WaitFailureHandler (UnbindInfo info)
Defined at line 106 of file ../../sdk/lib/fidl/cpp/wire/async_binding.cc
std::optional<DispatchError> Dispatch (fidl::IncomingHeaderAndMessage & msg, bool * next_wait_begun_early, internal::MessageStorageViewBase * storage_view)
Dispatches a generic incoming message.
## Message ownership
The client async binding should invoke the matching response handler or
event handler, if one is found. |msg| is then consumed, regardless of
decoding error.
The server async binding should invoke the matching request handler if
one is found. |msg| is then consumed, regardless of decoding error.
In other cases (e.g. unknown message, epitaph), |msg| is not consumed.
The caller should simply ignore the |fidl::IncomingHeaderAndMessage| object once
it is passed to this function, letting RAII clean up handles as needed.
## Return value
If errors occur during dispatching, the function will return an
|DispatchError| describing the error. Otherwise, it will return
|std::nullopt|.
If `*next_wait_begun_early` is set, the calling code no longer has ownership of
this |AsyncBinding| object and so must not access its state.
void InitKeepAlive ()
|InitKeepAlive| must be called after a concrete subclass is constructed
in a shared pointer, to set up the initial circular keep-alive reference.
Defined at line 163 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/async_binding.h
async_dispatcher_t * dispatcher ()
Defined at line 204 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/async_binding.h
TeardownTaskPostingResult StartTeardownWithInfo (std::shared_ptr<AsyncBinding> && calling_ref, UnbindInfo info)
Initiates teardown with the provided |info| as reason.
This does not have to happen in the context of a dispatcher thread.
Defined at line 205 of file ../../sdk/lib/fidl/cpp/wire/async_binding.cc
const DebugOnlySynchronizationChecker & thread_checker ()
Defined at line 206 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/async_binding.h
ThreadingPolicy threading_policy ()
Defined at line 208 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/async_binding.h
Enumerations
enum TeardownTaskPostingError
| Name | Value |
|---|---|
| kRacedWithInProgressTeardown | 0 |
| kDispatcherError | 1 |
|StartTeardownWithInfo| attempts to post exactly one task to drive the
teardown process. This enum reflects the result of posting the task.
Defined at line 113 of file ../../sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/async_binding.h