48 lines
1.2 KiB
Zig
48 lines
1.2 KiB
Zig
const std = @import("std");
|
|
const transport = @import("crasa-transport");
|
|
const zargs = @import("zargs");
|
|
const log = transport.logging.log;
|
|
|
|
const Config = struct {
|
|
port: u16 = 9700,
|
|
|
|
pub const meta = .{
|
|
.port = .{
|
|
.short = 'p',
|
|
.help = "UDP port",
|
|
},
|
|
};
|
|
};
|
|
|
|
pub fn main() !void {
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
defer _ = gpa.deinit();
|
|
const allocator = gpa.allocator();
|
|
zargs.setAllocator(allocator);
|
|
defer zargs.shutdown();
|
|
|
|
const config = try zargs.parse(Config);
|
|
const argv = try std.process.argsAlloc(allocator);
|
|
defer std.process.argsFree(allocator, argv);
|
|
|
|
if (zargs.isHelp()) {
|
|
const help_text = try zargs.getUsageAlloc("test-server");
|
|
defer allocator.free(help_text);
|
|
std.debug.print("{s}", .{help_text});
|
|
return;
|
|
}
|
|
|
|
log.info("server startup argc={d} port={d}", .{ argv.len, config.port });
|
|
for (argv, 0..) |arg, i| {
|
|
log.info("server argv[{d}]={s}", .{ i, arg });
|
|
}
|
|
|
|
const engine = try transport.UdpEngine.create(allocator);
|
|
defer engine.destroy();
|
|
try engine.serve(config.port);
|
|
|
|
while (!engine.shouldExit()) {
|
|
std.Thread.sleep(500 * std.time.ns_per_ms);
|
|
}
|
|
}
|