class Connection

Defined at line 48 of file ../../src/storage/lib/vfs/cpp/connection/connection.h

Connection is a base class representing an open connection to a Vnode (the server-side component

of a file descriptor). It contains the logic to synchronize connection teardown with the vfs, as

well as shared utilities such as connection cloning and enforcement of connection rights.

Connections will be managed in a |fbl::DoublyLinkedList|.

This class does not implement any FIDL generated C++ interfaces per se. Rather, each

|fuchsia.io/{Node, File, Directory, ...}| protocol is handled by a separate corresponding

subclass, potentially delegating shared functionalities back here.

The Vnode's methods will be invoked in response to FIDL protocol messages received over the

channel.

This class is thread-safe, although only a single-threaded dispatcher is supported.

Public Methods

void ~Connection ()

Closes the connection.

The connection must not be destroyed if its wait handler is running concurrently on another

thread.

In practice, this means the connection must have already been remotely closed, or it must be

destroyed on the wait handler's dispatch thread to prevent a race.

Defined at line 48 of file ../../src/storage/lib/vfs/cpp/connection/connection.cc

void Bind (zx::channel channel, OnUnbound on_unbound)

Begins waiting for messages on the channel. |channel| is the channel on which the FIDL protocol

will be served. Once called, connections are responsible for closing the underlying vnode.

Before calling this function, the connection ownership must be transferred to the Vfs through

|RegisterConnection|. Cannot be called more than once in the lifetime of the connection.

Defined at line 66 of file ../../src/storage/lib/vfs/cpp/connection/connection.h

void Unbind ()

Triggers asynchronous closure of the receiver. Will invoke the |on_unbound| callback passed to

|Bind| after unbinding the FIDL server from the channel. Implementations should close the vnode

if required once unbinding the server. If not bound or already unbound, has no effect.

Implementations *must* be thread-safe.

zx::result<> WithRepresentation (fit::callback<zx::result<> (fuchsia_io::wire::Representation)> handler, std::optional<fuchsia_io::NodeAttributesQuery> query)

Invokes |handler| with the Representation event for this connection. |query| specifies which

attributes, if any, should be included with the event. Returns the result of |handler| once

the given |query| is satisfied.

zx_status_t WithNodeInfoDeprecated (fit::callback<zx_status_t (fuchsia_io::wire::NodeInfoDeprecated)> handler)

Invokes |handler| with the NodeInfoDeprecated event for this connection.

const fbl::RefPtr<fs::Vnode> & vnode ()

Defined at line 90 of file ../../src/storage/lib/vfs/cpp/connection/connection.h

FuchsiaVfs::SharedPtr vfs ()

Defined at line 92 of file ../../src/storage/lib/vfs/cpp/connection/connection.h

Protected Methods

void Connection (fs::FuchsiaVfs * vfs, fbl::RefPtr<fs::Vnode> vnode, fuchsia_io::Rights rights)

Create a connection bound to a particular vnode.

The VFS will be notified when remote side closes the connection.

|vfs| is the VFS which is responsible for dispatching operations to the vnode.

|vnode| is the vnode which will handle I/O requests.

|rights| are the resulting rights for this connection.

Defined at line 42 of file ../../src/storage/lib/vfs/cpp/connection/connection.cc

void BindImpl (zx::channel channel, OnUnbound on_unbound)

Begin waiting for messages on the channel. |channel| is the channel on which the FIDL protocol

will be served. Should only be called once per connection.

void NodeClone (fuchsia_io::Flags flags, zx::channel object)

Node operations. Note that these provide the shared implementation of |fuchsia.io/Node|

methods, used by all connection subclasses. Use caution when working with FIDL wire types,

as certain wire types may reference external data.

Defined at line 56 of file ../../src/storage/lib/vfs/cpp/connection/connection.cc

zx::result<> NodeUpdateAttributes (const VnodeAttributesUpdate & update)

Defined at line 72 of file ../../src/storage/lib/vfs/cpp/connection/connection.cc

zx::result<fuchsia_io::wire::FilesystemInfo> NodeQueryFilesystem ()

Defined at line 86 of file ../../src/storage/lib/vfs/cpp/connection/connection.cc

const fuchsia_io::Rights & rights ()

Defined at line 104 of file ../../src/storage/lib/vfs/cpp/connection/connection.h

zx::event & token ()

Defined at line 106 of file ../../src/storage/lib/vfs/cpp/connection/connection.h

zx::result<> CloseVnode (zx_koid_t file_lock_koid)

Closes the vnode. Safe to be called if the vnode has already been closed. This should only be

called from the dispatcher thread.

Defined at line 122 of file ../../src/storage/lib/vfs/cpp/connection/connection.h