[Yunq] Release server cap on destructor.
This commit is contained in:
parent
43d7bfa7ad
commit
96a2f74e14
|
@ -8,7 +8,9 @@
|
|||
|
||||
|
||||
|
||||
|
||||
glcr::ErrorCode DenaliClient::Read(const ReadRequest& request, ReadResponse& response) {
|
||||
|
||||
uint64_t buffer_size = kBufferSize;
|
||||
uint64_t cap_size = kCapBufferSize;
|
||||
|
||||
|
@ -17,7 +19,10 @@ glcr::ErrorCode DenaliClient::Read(const ReadRequest& request, ReadResponse& res
|
|||
buffer_.WriteAt<uint64_t>(8, 0);
|
||||
|
||||
cap_buffer_.Reset();
|
||||
|
||||
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
|
||||
|
||||
|
||||
buffer_.WriteAt<uint32_t>(4, 16 + length);
|
||||
|
||||
z_cap_t reply_port_cap;
|
||||
|
@ -33,14 +38,18 @@ glcr::ErrorCode DenaliClient::Read(const ReadRequest& request, ReadResponse& res
|
|||
// Check Response Code.
|
||||
RET_ERR(buffer_.At<uint64_t>(8));
|
||||
|
||||
|
||||
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
||||
|
||||
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
glcr::ErrorCode DenaliClient::ReadMany(const ReadManyRequest& request, ReadResponse& response) {
|
||||
|
||||
uint64_t buffer_size = kBufferSize;
|
||||
uint64_t cap_size = kCapBufferSize;
|
||||
|
||||
|
@ -49,7 +58,10 @@ glcr::ErrorCode DenaliClient::ReadMany(const ReadManyRequest& request, ReadRespo
|
|||
buffer_.WriteAt<uint64_t>(8, 1);
|
||||
|
||||
cap_buffer_.Reset();
|
||||
|
||||
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
|
||||
|
||||
|
||||
buffer_.WriteAt<uint32_t>(4, 16 + length);
|
||||
|
||||
z_cap_t reply_port_cap;
|
||||
|
@ -65,8 +77,10 @@ glcr::ErrorCode DenaliClient::ReadMany(const ReadManyRequest& request, ReadRespo
|
|||
// Check Response Code.
|
||||
RET_ERR(buffer_.At<uint64_t>(8));
|
||||
|
||||
|
||||
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
||||
|
||||
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,13 @@ class DenaliClient {
|
|||
z_cap_t Capability() { return endpoint_; }
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode Read(const ReadRequest& request, ReadResponse& response);
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode ReadMany(const ReadManyRequest& request, ReadResponse& response);
|
||||
|
||||
|
||||
private:
|
||||
z_cap_t endpoint_;
|
||||
|
|
|
@ -29,6 +29,12 @@ void DenaliServerBaseThreadBootstrap(void* server_base) {
|
|||
((DenaliServerBase*)server_base)->ServerThread();
|
||||
}
|
||||
|
||||
DenaliServerBase::~DenaliServerBase() {
|
||||
if (endpoint_ != 0) {
|
||||
check(ZCapRelease(endpoint_));
|
||||
}
|
||||
}
|
||||
|
||||
glcr::ErrorOr<DenaliClient> DenaliServerBase::CreateClient() {
|
||||
uint64_t client_cap;
|
||||
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
|
||||
|
@ -87,25 +93,43 @@ glcr::ErrorCode DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
|||
|
||||
switch(method_select) {
|
||||
case 0: {
|
||||
|
||||
|
||||
ReadRequest yunq_request;
|
||||
ReadResponse yunq_response;
|
||||
|
||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
||||
|
||||
|
||||
|
||||
ReadResponse yunq_response;
|
||||
|
||||
|
||||
|
||||
RET_ERR(HandleRead(yunq_request, yunq_response));
|
||||
|
||||
|
||||
|
||||
resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps);
|
||||
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
|
||||
|
||||
ReadManyRequest yunq_request;
|
||||
ReadResponse yunq_response;
|
||||
|
||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
||||
|
||||
|
||||
|
||||
ReadResponse yunq_response;
|
||||
|
||||
|
||||
|
||||
RET_ERR(HandleReadMany(yunq_request, yunq_response));
|
||||
|
||||
|
||||
|
||||
resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps);
|
||||
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
|
|
@ -15,17 +15,22 @@ class DenaliServerBase {
|
|||
DenaliServerBase(z_cap_t Denali_cap) : endpoint_(Denali_cap) {}
|
||||
DenaliServerBase(const DenaliServerBase&) = delete;
|
||||
DenaliServerBase(DenaliServerBase&&) = delete;
|
||||
virtual ~DenaliServerBase();
|
||||
|
||||
glcr::ErrorOr<DenaliClient> CreateClient();
|
||||
|
||||
[[nodiscard]] Thread RunServer();
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] virtual glcr::ErrorCode HandleRead(const ReadRequest&, ReadResponse&) = 0;
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] virtual glcr::ErrorCode HandleReadMany(const ReadManyRequest&, ReadResponse&) = 0;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
z_cap_t endpoint_;
|
||||
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
|
||||
|
||||
|
||||
|
||||
glcr::ErrorCode VFSClient::OpenFile(const OpenFileRequest& request, OpenFileResponse& response) {
|
||||
|
||||
uint64_t buffer_size = kBufferSize;
|
||||
uint64_t cap_size = kCapBufferSize;
|
||||
|
||||
|
@ -17,7 +19,10 @@ glcr::ErrorCode VFSClient::OpenFile(const OpenFileRequest& request, OpenFileResp
|
|||
buffer_.WriteAt<uint64_t>(8, 0);
|
||||
|
||||
cap_buffer_.Reset();
|
||||
|
||||
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
|
||||
|
||||
|
||||
buffer_.WriteAt<uint32_t>(4, 16 + length);
|
||||
|
||||
z_cap_t reply_port_cap;
|
||||
|
@ -33,14 +38,18 @@ glcr::ErrorCode VFSClient::OpenFile(const OpenFileRequest& request, OpenFileResp
|
|||
// Check Response Code.
|
||||
RET_ERR(buffer_.At<uint64_t>(8));
|
||||
|
||||
|
||||
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
||||
|
||||
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
glcr::ErrorCode VFSClient::GetDirectory(const GetDirectoryRequest& request, Directory& response) {
|
||||
|
||||
uint64_t buffer_size = kBufferSize;
|
||||
uint64_t cap_size = kCapBufferSize;
|
||||
|
||||
|
@ -49,7 +58,10 @@ glcr::ErrorCode VFSClient::GetDirectory(const GetDirectoryRequest& request, Dire
|
|||
buffer_.WriteAt<uint64_t>(8, 1);
|
||||
|
||||
cap_buffer_.Reset();
|
||||
|
||||
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
|
||||
|
||||
|
||||
buffer_.WriteAt<uint32_t>(4, 16 + length);
|
||||
|
||||
z_cap_t reply_port_cap;
|
||||
|
@ -65,8 +77,10 @@ glcr::ErrorCode VFSClient::GetDirectory(const GetDirectoryRequest& request, Dire
|
|||
// Check Response Code.
|
||||
RET_ERR(buffer_.At<uint64_t>(8));
|
||||
|
||||
|
||||
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
||||
|
||||
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,13 @@ class VFSClient {
|
|||
z_cap_t Capability() { return endpoint_; }
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode OpenFile(const OpenFileRequest& request, OpenFileResponse& response);
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode GetDirectory(const GetDirectoryRequest& request, Directory& response);
|
||||
|
||||
|
||||
private:
|
||||
z_cap_t endpoint_;
|
||||
|
|
|
@ -29,6 +29,12 @@ void VFSServerBaseThreadBootstrap(void* server_base) {
|
|||
((VFSServerBase*)server_base)->ServerThread();
|
||||
}
|
||||
|
||||
VFSServerBase::~VFSServerBase() {
|
||||
if (endpoint_ != 0) {
|
||||
check(ZCapRelease(endpoint_));
|
||||
}
|
||||
}
|
||||
|
||||
glcr::ErrorOr<VFSClient> VFSServerBase::CreateClient() {
|
||||
uint64_t client_cap;
|
||||
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
|
||||
|
@ -87,25 +93,43 @@ glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
|||
|
||||
switch(method_select) {
|
||||
case 0: {
|
||||
|
||||
|
||||
OpenFileRequest yunq_request;
|
||||
OpenFileResponse yunq_response;
|
||||
|
||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
||||
|
||||
|
||||
|
||||
OpenFileResponse yunq_response;
|
||||
|
||||
|
||||
|
||||
RET_ERR(HandleOpenFile(yunq_request, yunq_response));
|
||||
|
||||
|
||||
|
||||
resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps);
|
||||
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
|
||||
|
||||
GetDirectoryRequest yunq_request;
|
||||
Directory yunq_response;
|
||||
|
||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
||||
|
||||
|
||||
|
||||
Directory yunq_response;
|
||||
|
||||
|
||||
|
||||
RET_ERR(HandleGetDirectory(yunq_request, yunq_response));
|
||||
|
||||
|
||||
|
||||
resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps);
|
||||
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
|
|
@ -15,17 +15,22 @@ class VFSServerBase {
|
|||
VFSServerBase(z_cap_t VFS_cap) : endpoint_(VFS_cap) {}
|
||||
VFSServerBase(const VFSServerBase&) = delete;
|
||||
VFSServerBase(VFSServerBase&&) = delete;
|
||||
virtual ~VFSServerBase();
|
||||
|
||||
glcr::ErrorOr<VFSClient> CreateClient();
|
||||
|
||||
[[nodiscard]] Thread RunServer();
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] virtual glcr::ErrorCode HandleOpenFile(const OpenFileRequest&, OpenFileResponse&) = 0;
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] virtual glcr::ErrorCode HandleGetDirectory(const GetDirectoryRequest&, Directory&) = 0;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
z_cap_t endpoint_;
|
||||
|
||||
|
|
|
@ -29,6 +29,12 @@ void VoyageursServerBaseThreadBootstrap(void* server_base) {
|
|||
((VoyageursServerBase*)server_base)->ServerThread();
|
||||
}
|
||||
|
||||
VoyageursServerBase::~VoyageursServerBase() {
|
||||
if (endpoint_ != 0) {
|
||||
check(ZCapRelease(endpoint_));
|
||||
}
|
||||
}
|
||||
|
||||
glcr::ErrorOr<VoyageursClient> VoyageursServerBase::CreateClient() {
|
||||
uint64_t client_cap;
|
||||
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
|
||||
|
|
|
@ -15,6 +15,7 @@ class VoyageursServerBase {
|
|||
VoyageursServerBase(z_cap_t Voyageurs_cap) : endpoint_(Voyageurs_cap) {}
|
||||
VoyageursServerBase(const VoyageursServerBase&) = delete;
|
||||
VoyageursServerBase(VoyageursServerBase&&) = delete;
|
||||
virtual ~VoyageursServerBase();
|
||||
|
||||
glcr::ErrorOr<VoyageursClient> CreateClient();
|
||||
|
||||
|
|
|
@ -29,6 +29,12 @@ void YellowstoneServerBaseThreadBootstrap(void* server_base) {
|
|||
((YellowstoneServerBase*)server_base)->ServerThread();
|
||||
}
|
||||
|
||||
YellowstoneServerBase::~YellowstoneServerBase() {
|
||||
if (endpoint_ != 0) {
|
||||
check(ZCapRelease(endpoint_));
|
||||
}
|
||||
}
|
||||
|
||||
glcr::ErrorOr<YellowstoneClient> YellowstoneServerBase::CreateClient() {
|
||||
uint64_t client_cap;
|
||||
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
|
||||
|
|
|
@ -15,6 +15,7 @@ class YellowstoneServerBase {
|
|||
YellowstoneServerBase(z_cap_t Yellowstone_cap) : endpoint_(Yellowstone_cap) {}
|
||||
YellowstoneServerBase(const YellowstoneServerBase&) = delete;
|
||||
YellowstoneServerBase(YellowstoneServerBase&&) = delete;
|
||||
virtual ~YellowstoneServerBase();
|
||||
|
||||
glcr::ErrorOr<YellowstoneClient> CreateClient();
|
||||
|
||||
|
|
|
@ -29,6 +29,12 @@ void {{interface.name}}ServerBaseThreadBootstrap(void* server_base) {
|
|||
(({{interface.name}}ServerBase*)server_base)->ServerThread();
|
||||
}
|
||||
|
||||
{{interface.name}}ServerBase::~{{interface.name}}ServerBase() {
|
||||
if (endpoint_ != 0) {
|
||||
check(ZCapRelease(endpoint_));
|
||||
}
|
||||
}
|
||||
|
||||
glcr::ErrorOr<{{interface.name}}Client> {{interface.name}}ServerBase::CreateClient() {
|
||||
uint64_t client_cap;
|
||||
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
|
||||
|
|
|
@ -15,6 +15,7 @@ class {{interface.name}}ServerBase {
|
|||
{{interface.name}}ServerBase(z_cap_t {{interface.name}}_cap) : endpoint_({{interface.name}}_cap) {}
|
||||
{{interface.name}}ServerBase(const {{interface.name}}ServerBase&) = delete;
|
||||
{{interface.name}}ServerBase({{interface.name}}ServerBase&&) = delete;
|
||||
virtual ~{{interface.name}}ServerBase();
|
||||
|
||||
glcr::ErrorOr<{{interface.name}}Client> CreateClient();
|
||||
|
||||
|
|
Loading…
Reference in New Issue