From 55652c0c0bbefee211ef9d685be20d2bb809a376 Mon Sep 17 00:00:00 2001 From: Jeeves Date: Tue, 25 Jun 2024 14:27:17 -0600 Subject: [PATCH] zig libvirt: fix Connection --- server/src/libvirt-connection.zig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/src/libvirt-connection.zig b/server/src/libvirt-connection.zig index 168aeaa..e802908 100644 --- a/server/src/libvirt-connection.zig +++ b/server/src/libvirt-connection.zig @@ -3,19 +3,22 @@ const mem = std.mem; const heap = std.heap; const c = @import("libvirt-c.zig").c; +const err = @import("libvirt-error.zig"); +const VirError = err.VirError; +const Connection = @This(); ptr: c.virConnectPtr, allocator: mem.Allocator, -pub fn connect(uri: []const u8, allocator: mem.Allocator) VirError!Connection { +pub fn init(uri: []const u8, allocator: mem.Allocator) VirError!Connection { const connection = c.virConnectOpenAuth(@ptrCast(uri), c.virConnectAuthPtrDefault, 0); if (connection) |conn| return .{ .ptr = conn, .allocator = allocator, - } else return handleError(); + } else return err.handleError(); } -pub fn close(self: *const Connection) void { +pub fn deinit(self: *const Connection) void { _ = c.virConnectClose(self.ptr); }