diff --git a/src/context.zig b/src/context.zig index 798d280..4af6417 100644 --- a/src/context.zig +++ b/src/context.zig @@ -74,10 +74,10 @@ pub const Context = struct { }; return Self{ .rundir = rundir - , .connections = Connections.init(allocator) - , .pollfd = PollFD.init(allocator) - , .tx = Messages.init(allocator) - , .switchdb = SwitchDB.init(allocator) + , .connections = Connections{} + , .pollfd = PollFD{} + , .tx = Messages{} + , .switchdb = SwitchDB.init(allocator) , .allocator = allocator }; } @@ -88,12 +88,12 @@ pub const Context = struct { }, }; self.allocator.free(self.rundir); - self.connections.deinit(); - self.pollfd.deinit(); + self.connections.deinit(self.allocator); + self.pollfd.deinit(self.allocator); for (self.tx.items) |m| { m.deinit(); } - self.tx.deinit(); + self.tx.deinit(self.allocator); self.switchdb.deinit(); } @@ -173,8 +173,8 @@ pub const Context = struct { /// in case one of the arrays cannot sustain another entry, the other /// won't be added. fn add_(self: *Self, new_connection: Connection, fd: posix.socket_t) !void { - try self.connections.append(new_connection); - try self.pollfd.append(.{ .fd = fd, .events = std.os.linux.POLL.IN, .revents = 0 }); + try self.connections.append(self.allocator, new_connection); + try self.pollfd.append(self.allocator, .{ .fd = fd, .events = std.os.linux.POLL.IN, .revents = 0 }); } fn fd_to_index(self: Self, fd: i32) !usize { @@ -253,7 +253,7 @@ pub const Context = struct { // While the program is running, the lock is enabled. // Once the program stops (even if it crashes), the lock is then disabled. // Quit if the lock is still active. - const lock_opts = .{ .lock = .exclusive, .lock_nonblocking = true }; + const lock_opts : std.fs.File.CreateFlags = .{ .lock = .exclusive, .lock_nonblocking = true }; _ = std.fs.createFileAbsolute(lock, lock_opts) catch |err| { log.err("cannot init server at {s}, lock {s} is causing a problem: {any}", .{ path, lock, err }); log.err("you may have lauched the service twice.", .{}); @@ -298,7 +298,7 @@ pub const Context = struct { } pub fn schedule(self: *Self, m: Message) !void { - try self.tx.append(m); + try self.tx.append(self.allocator, m); } /// Read from a client (indexed by a FD). @@ -317,8 +317,8 @@ pub const Context = struct { } pub fn set_switch_callbacks(self: *Self, fd: i32, - in: ?*const fn (origin: i32, mcontent: [*]u8, mlen: *usize) callconv(.C) u8, - out: ?*const fn (origin: i32, mcontent: [*]const u8, mlen: usize) callconv(.C) u8) !void { + in: ?*const fn (origin: i32, mcontent: [*]u8, mlen: *usize) callconv(.c) u8, + out: ?*const fn (origin: i32, mcontent: [*]const u8, mlen: usize) callconv(.c) u8) !void { try self.switchdb.set_callbacks(fd, in, out); } diff --git a/src/main.zig b/src/main.zig index 3dc5078..c2ebec0 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,17 +1,17 @@ -pub const CBEvent = @import("./callback.zig").CBEvent; -pub const Connection = @import("./connection.zig").Connection; -pub const Message = @import("./message.zig").Message; -pub const Event = @import("./event.zig").Event; -pub const Switch = @import("./switch.zig").Switch; - -pub const Messages = @import("./message.zig").Messages; -pub const Switches = @import("./switch.zig").Switches; -pub const Connections = @import("./connection.zig").Connections; -pub const Context = @import("./context.zig").Context; - -pub const util = @import("./util.zig"); -pub const hexdump = @import("./hexdump.zig"); -pub const exchangefd = @import("./exchange-fd.zig"); +// pub const CBEvent = @import("./callback.zig").CBEvent; +// pub const Connection = @import("./connection.zig").Connection; +// pub const Message = @import("./message.zig").Message; +// pub const Event = @import("./event.zig").Event; +// pub const Switch = @import("./switch.zig").Switch; +// +// pub const Messages = @import("./message.zig").Messages; +// pub const Switches = @import("./switch.zig").Switches; +// pub const Connections = @import("./connection.zig").Connections; +// pub const Context = @import("./context.zig").Context; +// +// pub const util = @import("./util.zig"); +// pub const hexdump = @import("./hexdump.zig"); +// pub const exchangefd = @import("./exchange-fd.zig"); // PING source code const std = @import("std"); diff --git a/src/switch.zig b/src/switch.zig index 1fd92a9..ea30eec 100644 --- a/src/switch.zig +++ b/src/switch.zig @@ -191,7 +191,7 @@ const ManagedConnection = struct { test "creation and display" { const config = .{ .safety = true }; - var gpa = std.heap.GeneralPurposeAllocator(config){}; + var gpa = std.heap.DebugAllocator(config){}; defer _ = gpa.deinit(); const allocator = gpa.allocator(); @@ -221,7 +221,7 @@ fn successful_out(_: i32, _: [*]const u8, _: usize) CBEventType { test "successful exchanges" { const config = .{ .safety = true }; - var gpa = std.heap.GeneralPurposeAllocator(config){}; + var gpa = std.heap.DebugAllocator(config){}; defer _ = gpa.deinit(); const allocator = gpa.allocator(); @@ -264,7 +264,7 @@ fn unsuccessful_out(_: i32, _: [*]const u8, _: usize) CBEventType { test "unsuccessful exchanges" { const config = .{ .safety = true }; - var gpa = std.heap.GeneralPurposeAllocator(config){}; + var gpa = std.heap.DebugAllocator(config){}; defer _ = gpa.deinit(); const allocator = gpa.allocator(); @@ -295,7 +295,7 @@ test "unsuccessful exchanges" { test "nuke 'em" { const config = .{ .safety = true }; - var gpa = std.heap.GeneralPurposeAllocator(config){}; + var gpa = std.heap.DebugAllocator(config){}; defer _ = gpa.deinit(); const allocator = gpa.allocator();