Obsolete
/
libipc-old
Archived
3
0
Fork 0

Deinit() some stuff.

master
Philippe Pittoli 2022-02-07 01:21:46 +01:00
parent 87f6f9071b
commit 69732ccad8
1 changed files with 13 additions and 3 deletions

View File

@ -293,11 +293,19 @@ pub const Context = struct {
} }
pub fn connect(self: *Self, path: []const u8) !void { pub fn connect(self: *Self, path: []const u8) !void {
print("connection to {s}", .{path}); print("connection to {s}\n", .{path});
var newcon = Connection.init(ConnectionType.IPC, path); var newcon = Connection.init(ConnectionType.IPC, path);
try self.connections.append(newcon); try self.connections.append(newcon);
} }
pub fn deinit(self: *Self) void {
print("connection deinit\n", .{});
self.connections.deinit();
self.tx.deinit();
if (self.switchdb) |sdb| { sdb.deinit(); }
self.tx.deinit();
}
pub fn format( pub fn format(
self: Self, self: Self,
comptime fmt: []const u8, comptime fmt: []const u8,
@ -309,10 +317,12 @@ pub const Context = struct {
, .{self.connections.items.len, self.tx.items.len}); , .{self.connections.items.len, self.tx.items.len});
for (self.connections.items) |con| { for (self.connections.items) |con| {
try std.fmt.format(out_stream, "\n- ", .{});
try con.format(fmt, options, out_stream); try con.format(fmt, options, out_stream);
} }
for (self.tx.items) |tx| { for (self.tx.items) |tx| {
try std.fmt.format(out_stream, "\n- ", .{});
try tx.format(fmt, options, out_stream); try tx.format(fmt, options, out_stream);
} }
} }
@ -328,11 +338,10 @@ test "Context - creation and display" {
const config = .{.safety = true}; const config = .{.safety = true};
var gpa = std.heap.GeneralPurposeAllocator(config){}; var gpa = std.heap.GeneralPurposeAllocator(config){};
defer _ = gpa.deinit(); // There. Can't leak. Isn't Zig wonderful? defer _ = gpa.deinit();
const allocator = gpa.allocator(); const allocator = gpa.allocator();
// var payload = "hello!!"; // var payload = "hello!!";
// // fd type usertype payload // // fd type usertype payload
// var m = Message.init(0, MessageType.DATA, 1, payload); // var m = Message.init(0, MessageType.DATA, 1, payload);
@ -341,6 +350,7 @@ test "Context - creation and display" {
// var e = Event.init(EventType.CONNECTION, 5, 8, &m); // var e = Event.init(EventType.CONNECTION, 5, 8, &m);
var c = Context.init(allocator); var c = Context.init(allocator);
defer c.deinit(); // There. Can't leak. Isn't Zig wonderful?
try c.connect("/somewhere/over/the/rainbow"); try c.connect("/somewhere/over/the/rainbow");