The library jumped to Zig v0.15.2 which implies a new build system. `build.zig` now compiles libipc as both static and dynamic libraries, and provides an entry point to use `libipc` as-is for Zig applications. Some examples have been added to help new users play with the library. Thanks to these fairly complete examples, two (very small) leaks related to sentinel values (in arrays containing paths) were fixed.
41 lines
1.2 KiB
Zig
41 lines
1.2 KiB
Zig
const std = @import("std");
|
|
const net = std.net;
|
|
const fmt = std.fmt;
|
|
|
|
const print_eq = @import("./util.zig").print_eq;
|
|
|
|
pub const Connections = std.ArrayList(Connection);
|
|
|
|
pub const Connection = struct {
|
|
pub const Type = enum {
|
|
IPC, // Standard connection.
|
|
EXTERNAL, // Non IPC connection (TCP, UDP, etc.).
|
|
SERVER, // Messages received = new connections.
|
|
SWITCHED, // IO operations should go through registered callbacks.
|
|
};
|
|
|
|
t: Connection.Type,
|
|
path: ?[:0]const u8, // Not always needed.
|
|
|
|
const Self = @This();
|
|
|
|
pub fn init(t: Connection.Type, path: ?[:0]const u8) Self {
|
|
return Self{
|
|
.t = t,
|
|
.path = path,
|
|
};
|
|
}
|
|
|
|
pub fn format(self: Self, comptime _: []const u8, _: fmt.FormatOptions, out_stream: anytype) !void {
|
|
try fmt.format(out_stream, "{}, path {?s}", .{ self.t, self.path });
|
|
}
|
|
};
|
|
|
|
test "Connection - creation and display" {
|
|
// origin destination
|
|
const path = "/some/path";
|
|
const c1 = Connection.init(Connection.Type.EXTERNAL, path);
|
|
const c2 = Connection.init(Connection.Type.IPC, null);
|
|
try print_eq("connection.Connection.Type.EXTERNAL, path /some/path", c1);
|
|
try print_eq("connection.Connection.Type.IPC, path null", c2);
|
|
}
|