[Yunq] Delete client capability in destructor.

Add a method to the server class to create an unowned capability. This
makes it simpler to create a capability for passing to other processes.

Duplicate the init yellowstone cap when using it temporarily.
This commit is contained in:
Drew Galbraith 2023-11-27 08:28:58 -08:00
parent 96a2f74e14
commit ad7794c694
24 changed files with 98 additions and 9 deletions

View file

@ -3,9 +3,17 @@
#include <glacier/buffer/byte_buffer.h>
#include <glacier/buffer/cap_buffer.h>
#include <mammoth/util/debug.h>
#include <zcall.h>
{% for interface in interfaces %}
{{interface.name}}Client::~{{interface.name}}Client() {
if (endpoint_ != 0) {
check(ZCapRelease(endpoint_));
}
}
{% for method in interface.methods %}
{% if method.request == None %}

View file

@ -14,6 +14,7 @@ class {{interface.name}}Client {
{{interface.name}}Client(z_cap_t {{interface.name}}_cap) : endpoint_({{interface.name}}_cap) {}
{{interface.name}}Client(const {{interface.name}}Client&) = delete;
{{interface.name}}Client({{interface.name}}Client&& other) : endpoint_(other.endpoint_) {other.endpoint_ = 0;};
~{{interface.name}}Client();
z_cap_t Capability() { return endpoint_; }

View file

@ -35,6 +35,12 @@ void {{interface.name}}ServerBaseThreadBootstrap(void* server_base) {
}
}
glcr::ErrorOr<z_cap_t> {{interface.name}}ServerBase::CreateClientCap() {
uint64_t client_cap;
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
return client_cap;
}
glcr::ErrorOr<{{interface.name}}Client> {{interface.name}}ServerBase::CreateClient() {
uint64_t client_cap;
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));

View file

@ -17,6 +17,7 @@ class {{interface.name}}ServerBase {
{{interface.name}}ServerBase({{interface.name}}ServerBase&&) = delete;
virtual ~{{interface.name}}ServerBase();
glcr::ErrorOr<z_cap_t> CreateClientCap();
glcr::ErrorOr<{{interface.name}}Client> CreateClient();
[[nodiscard]] Thread RunServer();