╭ changed ────╮ │src/serve.zig│ ╰─────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭───────────────────────────────────────╮ │4 const hash = xit.hash; │ │5 const ui = @import("./ui.zig"); │ │6 const web = @import("./web.zig"); │ │7 - │ │8 -const wui_listen = "127.0.0.1:8082";│ │7 │ │8 pub const Options = struct { │ │9 http_listen: []const u8, │ ╰───────────────────────────────────────╯ ╭────────────────────────────────╮ │12 - ssh_listen: ?[]const u8,│ │10 + ssh_listen: []const u8, │ │11 + wui_listen: []const u8, │ │12 data_dir: []const u8, │ │13 tui: bool, │ │14 }; │ ╰────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │51 │ │52 // create ssh listener │ │53 │ │55 - var ssh_server: ?std.Io.net.Server = null; │ │56 - defer if (ssh_server) |*server| server.deinit(io); │ │57 - │ │58 - if (options.ssh_listen) |ssh_listen| { │ │59 - const ssh_listen_address = try parseListenAddress(ssh_listen); │ │60 - const ssh_address = try std.Io.net.IpAddress.parseIp4(ssh_listen_address.host, ssh_listen_address.port);│ │61 - ssh_server = try ssh_address.listen(io, .{ .reuse_address = true }); │ │62 - } │ │54 + const ssh_listen_address = try parseListenAddress(options.ssh_listen); │ │55 + const ssh_address = try std.Io.net.IpAddress.parseIp4(ssh_listen_address.host, ssh_listen_address.port); │ │56 + var ssh_server = try ssh_address.listen(io, .{ .reuse_address = true }); │ │57 + defer ssh_server.deinit(io); │ │58 │ │59 // create wui listener │ │60 │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │66 - const wui_listen_address = try parseListenAddress(wui_listen); │ │61 + const wui_listen_address = try parseListenAddress(options.wui_listen); │ │62 const wui_address = try std.Io.net.IpAddress.parseIp4(wui_listen_address.host, wui_listen_address.port);│ │63 var wui_server = try wui_address.listen(io, .{ .reuse_address = true }); │ │64 defer wui_server.deinit(io); │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────╮ │65 │ │66 + // start task group │ │67 + │ │68 var tasks: std.Io.Group = .init;│ │69 defer tasks.cancel(io); │ │70 │ ╰────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │71 + // run listeners │ │72 + │ │73 try err.print("serving HTTP on {s}, repo root {s}\n", .{ options.http_listen, repo_root_path });│ │74 try err.flush(); │ │75 │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │76 runHttpListener(repo_kind, any_repo_opts, io, allocator, repo_root_path, &http_server, &tasks, err); │ │77 │ │79 - if (options.ssh_listen) |ssh_listen| { │ │80 - try err.print("serving SSH helper connections on {s}, repo root {s}\n", .{ ssh_listen, repo_root_path }); │ │81 - try err.flush(); │ │78 + try err.print("serving SSH helper connections on {s}, repo root {s}\n", .{ options.ssh_listen, repo_root_path });│ │79 + try err.flush(); │ │80 │ │83 - const server = &(ssh_server orelse return error.MissingSshServer); │ │84 - runSshListener(repo_kind, any_repo_opts, io, allocator, repo_root_path, server, &tasks, err); │ │85 - } │ │81 + runSshListener(repo_kind, any_repo_opts, io, allocator, repo_root_path, &ssh_server, &tasks, err); │ │82 │ │87 - try err.print("serving web UI on http://{s}/\n", .{wui_listen}); │ │83 + try err.print("serving web UI on http://{s}/\n", .{options.wui_listen}); │ │84 try err.flush(); │ │85 │ │86 web.run(io, &wui_server, &tasks, err); │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯