gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain10f8a8c8Merge branch 'code-order' into mainJukeboxmain/plugins/http/http_common.zig

22.2 KB

  1. // Shared HTTP utilities — compiled into each HTTP plugin at build time
  2. // Not a standalone plugin .so, but a Zig module imported by hl:http1, hl:http2, hl:http3
  3. const std = @import("std");
  4. const api = @import("plugin_api");
  5. pub const HlString = api.HlString;
  6. pub fn hlStr(s: []const u8) HlString {
  7. return .{ .ptr = s.ptr, .len = s.len };
  8. }
  9. pub fn statusReason(code: u16) []const u8 {
  10. return switch (code) {
  11. 200 => "OK",
  12. 201 => "Created",
  13. 204 => "No Content",
  14. 301 => "Moved Permanently",
  15. 302 => "Found",
  16. 304 => "Not Modified",
  17. 400 => "Bad Request",
  18. 401 => "Unauthorized",
  19. 403 => "Forbidden",
  20. 404 => "Not Found",
  21. 405 => "Method Not Allowed",
  22. 409 => "Conflict",
  23. 413 => "Payload Too Large",
  24. 415 => "Unsupported Media Type",
  25. 422 => "Unprocessable Entity",
  26. 429 => "Too Many Requests",
  27. 500 => "Internal Server Error",
  28. 502 => "Bad Gateway",
  29. 503 => "Service Unavailable",
  30. 504 => "Gateway Timeout",
  31. else => "OK",
  32. };
  33. }
  34. /// Decode percent-encoded URL components (%20 → space, etc.)
  35. pub fn urlDecode(allocator: anytype, input: []const u8) ![]u8 {
  36. var result = try allocator.alloc(u8, input.len);
  37. var out: usize = 0;
  38. var i: usize = 0;
  39. while (i < input.len) {
  40. if (input[i] == '%' and i + 2 < input.len) {
  41. const hi = hexVal(input[i + 1]) orelse {
  42. result[out] = input[i];
  43. out += 1;
  44. i += 1;
  45. continue;
  46. };
  47. const lo = hexVal(input[i + 2]) orelse {
  48. result[out] = input[i];
  49. out += 1;
  50. i += 1;
  51. continue;
  52. };
  53. result[out] = (@as(u8, hi) << 4) | @as(u8, lo);
  54. out += 1;
  55. i += 3;
  56. } else if (input[i] == '+') {
  57. result[out] = ' ';
  58. out += 1;
  59. i += 1;
  60. } else {
  61. result[out] = input[i];
  62. out += 1;
  63. i += 1;
  64. }
  65. }
  66. return result[0..out];
  67. }
  68. fn hexVal(c: u8) ?u4 {
  69. if (c >= '0' and c <= '9') return @intCast(c - '0');
  70. if (c >= 'a' and c <= 'f') return @intCast(c - 'a' + 10);
  71. if (c >= 'A' and c <= 'F') return @intCast(c - 'A' + 10);
  72. return null;
  73. }
  74. /// Split a query string into key-value pairs.
  75. /// Returns allocated slices that must be freed by the caller.
  76. pub fn parseQueryString(alloc: anytype, query: []const u8) ![]QueryParam {
  77. var params: @import("std").ArrayListUnmanaged(QueryParam) = .empty;
  78. var iter = @import("std").mem.splitScalar(u8, query, '&');
  79. while (iter.next()) |pair| {
  80. if (pair.len == 0) continue;
  81. if (@import("std").mem.indexOfScalar(u8, pair, '=')) |eq| {
  82. const key = try urlDecode(alloc, pair[0..eq]);
  83. const val = try urlDecode(alloc, pair[eq + 1 ..]);
  84. try params.append(alloc, .{ .key = key, .value = val });
  85. } else {
  86. const key = try urlDecode(alloc, pair);
  87. try params.append(alloc, .{ .key = key, .value = &[_]u8{} });
  88. }
  89. }
  90. return params.toOwnedSlice(alloc);
  91. }
  92. pub const QueryParam = struct {
  93. key: []u8,
  94. value: []u8,
  95. };
  96. /// Lowercase a header key in-place (HTTP/1.1 headers are case-insensitive)
  97. pub fn toLowercase(buf: []u8) void {
  98. for (buf) |*ch| {
  99. if (ch.* >= 'A' and ch.* <= 'Z') {
  100. ch.* = ch.* + 32;
  101. }
  102. }
  103. }
  104. // ---------------------------------------------------------------------------
  105. // RESPONSE HEADERS WITH MORE THAN ONE VALUE (ticket #222) — ONE implementation
  106. // for hl:http1, hl:http2 and hl:http3, so the three cannot drift.
  107. //
  108. // A header value in a Response may be a String (one header line) or an Array of
  109. // Strings (one header line, or one HTTP/2 / HTTP/3 field, per entry). An array
  110. // crosses the plugin boundary as an object keyed "0".."n-1", so any object value
  111. // is read as a list; entries that are not strings are skipped, an empty list
  112. // writes nothing. Names are compared WITHOUT regard to case: keys that differ
  113. // only in case ("Set-Cookie" and "set-cookie") are merged into one list in the
  114. // order they were written, and sit where the first of them stood, under the
  115. // spelling of that first one. Values are never joined into one comma line:
  116. // that is wrong for Set-Cookie.
  117. // ---------------------------------------------------------------------------
  118. /// Call `sink.add(name, value)` once per header line the headers object `obj`
  119. /// stands for. `sink` is any pointer with an `add([]const u8, []const u8) void`.
  120. pub fn eachHeaderLine(obj: *const api.HlObject, sink: anytype) void {
  121. const fields = obj.fields[0..obj.field_count];
  122. for (fields, 0..) |field, i| {
  123. if (field.value.type != .hl_string and field.value.type != .hl_object) continue;
  124. const name = field.key.ptr[0..field.key.len];
  125. // an earlier key of the same name (in any case) already wrote this one's values
  126. var seen = false;
  127. for (fields[0..i]) |prev| {
  128. if (prev.value.type != .hl_string and prev.value.type != .hl_object) continue;
  129. if (std.ascii.eqlIgnoreCase(prev.key.ptr[0..prev.key.len], name)) {
  130. seen = true;
  131. break;
  132. }
  133. }
  134. if (seen) continue;
  135. for (fields[i..]) |same| {
  136. if (!std.ascii.eqlIgnoreCase(same.key.ptr[0..same.key.len], name)) continue;
  137. switch (same.value.type) {
  138. .hl_string => sink.add(name, same.value.data.string.ptr[0..same.value.data.string.len]),
  139. .hl_object => {
  140. const list = same.value.data.object;
  141. for (list.fields[0..list.field_count]) |item| {
  142. if (item.value.type == .hl_string) sink.add(name, item.value.data.string.ptr[0..item.value.data.string.len]);
  143. }
  144. },
  145. else => {},
  146. }
  147. }
  148. }
  149. }
  150. const TestSink = struct {
  151. out: std.ArrayListUnmanaged(u8) = .empty,
  152. pub fn add(self: *TestSink, name: []const u8, value: []const u8) void {
  153. self.out.appendSlice(std.testing.allocator, name) catch {};
  154. self.out.appendSlice(std.testing.allocator, "=") catch {};
  155. self.out.appendSlice(std.testing.allocator, value) catch {};
  156. self.out.appendSlice(std.testing.allocator, ";") catch {};
  157. }
  158. };
  159. test "eachHeaderLine: lists, case-merge, order" {
  160. var cookies = [_]api.HlField{
  161. .{ .key = hlStr("0"), .value = api.makeString("a=1") },
  162. .{ .key = hlStr("1"), .value = api.makeString("b=2") },
  163. };
  164. var list = api.HlObject{ .fields = &cookies, .field_count = 2, .deinit_fn = null };
  165. var fields = [_]api.HlField{
  166. .{ .key = hlStr("Set-Cookie"), .value = api.makeObject(&list) },
  167. .{ .key = hlStr("X-One"), .value = api.makeString("1") },
  168. .{ .key = hlStr("set-cookie"), .value = api.makeString("c=3") },
  169. };
  170. var obj = api.HlObject{ .fields = &fields, .field_count = 3, .deinit_fn = null };
  171. var sink = TestSink{};
  172. defer sink.out.deinit(std.testing.allocator);
  173. eachHeaderLine(&obj, &sink);
  174. try std.testing.expectEqualStrings("Set-Cookie=a=1;Set-Cookie=b=2;Set-Cookie=c=3;X-One=1;", sink.out.items);
  175. }
  176. // ---------------------------------------------------------------------------
  177. // RESPONSE BODY COMPRESSION (creator, 2026-08-15) — a TRANSPORT concern, like
  178. // TLS: nobody writes compression in app code; a server honors Accept-Encoding.
  179. // ONE implementation here (decision D8's pattern), each plugin adds only its
  180. // own framing. gzip via Zig std flate — no external library.
  181. // ---------------------------------------------------------------------------
  182. /// Below this a gzip header+footer is overhead, not savings (canonical ~860
  183. /// from Akamai's measurements; MTU-fitting responses gain nothing).
  184. pub const compress_min_len = 860;
  185. /// The texty content types worth compressing, decided from the Content-Type
  186. /// VALUE. Already-compressed formats (images, fonts, archives) get bigger, not
  187. /// smaller. hl:http2 and hl:http3 carry headers as key/value pairs rather than
  188. /// h1's raw blob, so this is the half they can ask.
  189. pub fn compressibleTypeValue(value: []const u8) bool {
  190. const v = std.mem.trim(u8, value, " ");
  191. return std.mem.startsWith(u8, v, "text/") or
  192. std.mem.startsWith(u8, v, "application/javascript") or
  193. std.mem.startsWith(u8, v, "application/json") or
  194. std.mem.startsWith(u8, v, "image/svg");
  195. }
  196. /// The same question asked of h1's assembled custom-header text.
  197. pub fn compressibleContentType(headers_blob: []const u8) bool {
  198. var it = std.mem.splitSequence(u8, headers_blob, "\r\n");
  199. while (it.next()) |line| {
  200. if (line.len > 13 and std.ascii.eqlIgnoreCase(line[0..13], "content-type:")) {
  201. return compressibleTypeValue(line[13..]);
  202. }
  203. if (line.len > 17 and std.ascii.eqlIgnoreCase(line[0..17], "content-encoding:")) return false;
  204. }
  205. // no Content-Type in custom headers → the plugin's default is text/html
  206. return true;
  207. }
  208. /// gzip `body`; null when compression does not pay (or fails — the caller then
  209. /// sends the identity bytes, which is always correct).
  210. pub fn gzipBody(allocator: std.mem.Allocator, body: []const u8) ?[]u8 {
  211. if (body.len < compress_min_len) return null;
  212. // Compress.init asserts `output.buffer.len > 8`, and a plain
  213. // Allocating.init starts EMPTY — the assert then panics on a worker thread
  214. // and kills the server after the first compressed response (found the hard
  215. // way 2026-08-15). initCapacity gives the writer its buffer up front.
  216. var out: std.Io.Writer.Allocating = std.Io.Writer.Allocating.initCapacity(allocator, 4096) catch return null;
  217. defer out.deinit();
  218. const window = allocator.alloc(u8, std.compress.flate.max_window_len) catch return null;
  219. defer allocator.free(window);
  220. // .level_6 — the documented setting; Options carries no defaults.
  221. var c = std.compress.flate.Compress.init(&out.writer, window, .gzip, .level_6) catch return null;
  222. c.writer.writeAll(body) catch return null;
  223. c.finish() catch return null;
  224. if (out.writer.buffered().len >= body.len) return null; // grew: send identity
  225. return allocator.dupe(u8, out.writer.buffered()) catch null;
  226. }
  227. // ── The mission-125 BELL: one eventfd per loop source ────────────────────────
  228. //
  229. // RESTORED 2026-08-29 (mission 257). `hl:fetch` and `hl:smtp` both call these by
  230. // name, and both had been UNBUILDABLE since the 2026-08-20 recovery replay
  231. // dropped them from this file — nothing noticed, because `native/build.zig` did
  232. // not build either plugin. See `native/src/loop_wait.zig` for the contract they
  233. // implement: the loop owns one epoll set over every source's `wake_fd`, adds it
  234. // LEVEL-triggered, and drains the counter itself right after `epoll_wait`. A
  235. // producer rings when it queues an event. A consumer returning only ONE item
  236. // must also re-ring under its queue lock while more remain: draining an
  237. // eventfd clears the entire counter, not just the returned item's signal.
  238. //
  239. // Raw syscalls rather than libc, so a plugin that does not link libc (hl:http1)
  240. // can still ring a bell.
  241. /// A source's wake fd: a non-blocking eventfd counter. `-1` on failure, which is
  242. /// the ABI's "no signal, keep polling" value — a plugin that cannot get an fd
  243. /// degrades to the polled path instead of failing to load.
  244. pub fn makeWakeFd() i32 {
  245. const rc = std.os.linux.eventfd(0, std.os.linux.EFD.NONBLOCK | std.os.linux.EFD.CLOEXEC);
  246. if (@as(isize, @bitCast(rc)) < 0) return -1;
  247. return @intCast(rc);
  248. }
  249. /// RING IT. Coalesced, duplicated or early wakes are harmless by design (a bell,
  250. /// not a routing key); only a wake that is never sent can be a bug — so producers
  251. /// ring generously and never reason about whether the loop "needs" it.
  252. pub fn ringWake(fd: i32) void {
  253. if (fd < 0) return;
  254. const one: u64 = 1;
  255. _ = std.os.linux.write(fd, @ptrCast(&one), @sizeOf(u64));
  256. }
  257. // ================================================================================
  258. // WHY A BIND FAILED — IN WORDS, AND WITH THE HOLDER'S NAME (mission 286)
  259. // ================================================================================
  260. // All three transports used to print the same six words — `bind() failed on port
  261. // N` — and drop the errno on the floor. Six words cannot be acted on: a port that
  262. // is taken, a port below 1024 without CAP_NET_BIND_SERVICE, and an address that is
  263. // not one of this machine's are three different mistakes with three different
  264. // fixes, and the kernel had already said which one it was.
  265. //
  266. // So the errno is named, and when it is EADDRINUSE the holder is looked up the way
  267. // an operator would look it up: `/proc/net/{tcp,tcp6,udp,udp6}` for the socket on
  268. // that port, then `/proc/<pid>/fd` for whoever owns its inode. It says "a process
  269. // this one cannot see" rather than guessing when the holder belongs to another
  270. // user — `/proc/<pid>/fd` is unreadable then, and a wrong name is worse than none.
  271. //
  272. // This costs nothing on the happy path: it runs once, on a boot that is about to
  273. // be refused.
  274. fn errnoWord(e: u32) []const u8 {
  275. return switch (e) {
  276. 13 => "EACCES",
  277. 22 => "EINVAL",
  278. 24 => "EMFILE",
  279. 97 => "EAFNOSUPPORT",
  280. 98 => "EADDRINUSE",
  281. 99 => "EADDRNOTAVAIL",
  282. else => "errno",
  283. };
  284. }
  285. fn errnoWhy(e: u32) []const u8 {
  286. return switch (e) {
  287. 13 => "permission denied — a port below 1024 needs CAP_NET_BIND_SERVICE or root",
  288. 22 => "invalid argument — this socket is already bound",
  289. 24 => "too many open files — the process fd limit is reached",
  290. 97 => "address family not supported",
  291. 98 => "the port is already in use",
  292. 99 => "that address is not one of this machine's",
  293. else => "the kernel refused the bind",
  294. };
  295. }
  296. fn hexNibble(c: u8) ?u8 {
  297. return switch (c) {
  298. '0'...'9' => c - '0',
  299. 'a'...'f' => c - 'a' + 10,
  300. 'A'...'F' => c - 'A' + 10,
  301. else => null,
  302. };
  303. }
  304. fn hexValue(s: []const u8) ?u64 {
  305. if (s.len == 0 or s.len > 16) return null;
  306. var v: u64 = 0;
  307. for (s) |c| v = (v << 4) | (hexNibble(c) orelse return null);
  308. return v;
  309. }
  310. /// `/proc/net/*`'s local_address column ("0100007F:1F90") as text the operator
  311. /// recognises. IPv4 is four little-endian bytes; anything longer is printed as the
  312. /// raw hex word rather than mis-rendered as a v6 address it may not be.
  313. fn writeProcAddr(out: []u8, hex: []const u8, port: u16) []const u8 {
  314. if (hex.len == 8) {
  315. const v = hexValue(hex) orelse return "";
  316. const b: [4]u8 = .{
  317. @truncate(v & 0xff),
  318. @truncate((v >> 8) & 0xff),
  319. @truncate((v >> 16) & 0xff),
  320. @truncate((v >> 24) & 0xff),
  321. };
  322. return std.fmt.bufPrint(out, "{d}.{d}.{d}.{d}:{d}", .{ b[0], b[1], b[2], b[3], port }) catch "";
  323. }
  324. return std.fmt.bufPrint(out, "[{s}]:{d}", .{ hex, port }) catch "";
  325. }
  326. // RAW SYSCALLS, for the same reason the wake bell above uses them: this file is
  327. // compiled INTO three plugins, `std.fs` in Zig 0.16 wants an `Io` interface these
  328. // plugins do not carry, and `/proc` is read once, at a boot that is failing.
  329. const lin = std.os.linux;
  330. fn sysOpen(path: [*:0]const u8, dir: bool) ?i32 {
  331. const rc = lin.open(path, .{ .ACCMODE = .RDONLY, .CLOEXEC = true, .DIRECTORY = dir }, 0);
  332. const fd: i64 = @bitCast(@as(u64, rc));
  333. if (fd < 0) return null;
  334. return @intCast(fd);
  335. }
  336. fn sysClose(fd: i32) void {
  337. _ = lin.close(fd);
  338. }
  339. const SocketOnPort = struct { inode: u64, addr_hex: [40]u8, addr_len: usize };
  340. /// The socket sitting on `port`, out of the four `/proc/net` tables. For TCP only a
  341. /// LISTEN socket (`st == 0A`) can block a bind — mission 285 measured that, squat by
  342. /// squat: TIME_WAIT and ESTABLISHED are tolerated because both sides set
  343. /// SO_REUSEADDR. UDP has no states worth filtering.
  344. fn socketOnPort(port: u16, udp: bool) ?SocketOnPort {
  345. const tables: [2][*:0]const u8 = if (udp)
  346. .{ "/proc/net/udp", "/proc/net/udp6" }
  347. else
  348. .{ "/proc/net/tcp", "/proc/net/tcp6" };
  349. for (tables) |path| {
  350. const fd = sysOpen(path, false) orelse continue;
  351. defer sysClose(fd);
  352. var chunk: [8192]u8 = undefined;
  353. var line: [512]u8 = undefined;
  354. var line_len: usize = 0;
  355. while (true) {
  356. const rc = lin.read(fd, &chunk, chunk.len);
  357. const got: i64 = @bitCast(@as(u64, rc));
  358. if (got <= 0) break;
  359. const n: usize = @intCast(got);
  360. for (chunk[0..n]) |ch| {
  361. if (ch != '\n') {
  362. if (line_len < line.len) {
  363. line[line_len] = ch;
  364. line_len += 1;
  365. }
  366. continue;
  367. }
  368. if (parseProcNetLine(line[0..line_len], port, udp)) |hit| return hit;
  369. line_len = 0;
  370. }
  371. }
  372. if (line_len > 0) {
  373. if (parseProcNetLine(line[0..line_len], port, udp)) |hit| return hit;
  374. }
  375. }
  376. return null;
  377. }
  378. /// One `/proc/net/*` row: `sl local rem st tx:rx tr:when retrnsmt uid timeout inode`.
  379. fn parseProcNetLine(line: []const u8, port: u16, udp: bool) ?SocketOnPort {
  380. var it = std.mem.tokenizeAny(u8, line, " \t");
  381. _ = it.next() orelse return null; // sl
  382. const local = it.next() orelse return null;
  383. _ = it.next() orelse return null; // rem_address
  384. const st = it.next() orelse return null;
  385. if (!udp and !std.mem.eql(u8, st, "0A")) return null;
  386. const colon = std.mem.lastIndexOfScalar(u8, local, ':') orelse return null;
  387. const lport = hexValue(local[colon + 1 ..]) orelse return null;
  388. if (lport != port) return null;
  389. var skipped: usize = 0;
  390. while (skipped < 5) : (skipped += 1) _ = it.next() orelse return null;
  391. const inode = std.fmt.parseInt(u64, it.next() orelse return null, 10) catch return null;
  392. const hex = local[0..colon];
  393. var hit = SocketOnPort{ .inode = inode, .addr_hex = undefined, .addr_len = 0 };
  394. if (hex.len > hit.addr_hex.len) return null;
  395. @memcpy(hit.addr_hex[0..hex.len], hex);
  396. hit.addr_len = hex.len;
  397. return hit;
  398. }
  399. /// Whoever has that socket inode open. An unreadable `/proc/<pid>/fd` is SKIPPED,
  400. /// not reported as absent: a holder owned by another user is invisible from here,
  401. /// and the caller says exactly that instead of naming the wrong process.
  402. fn pidHolding(inode: u64, name_out: []u8, name_len: *usize) ?u32 {
  403. const proc_fd = sysOpen("/proc", true) orelse return null;
  404. defer sysClose(proc_fd);
  405. var want: [48]u8 = undefined;
  406. const want_link = std.fmt.bufPrint(&want, "socket:[{d}]", .{inode}) catch return null;
  407. var ents: [8192]u8 align(8) = undefined;
  408. while (true) {
  409. const rc = lin.getdents64(proc_fd, &ents, ents.len);
  410. const got: i64 = @bitCast(@as(u64, rc));
  411. if (got <= 0) return null;
  412. var off: usize = 0;
  413. while (off < @as(usize, @intCast(got))) {
  414. const ent: *align(1) const lin.dirent64 = @ptrCast(&ents[off]);
  415. off += ent.reclen;
  416. const name_ptr: [*:0]const u8 = @ptrCast(&ent.name);
  417. const pid = std.fmt.parseInt(u32, std.mem.span(name_ptr), 10) catch continue;
  418. if (fdsHold(pid, want_link)) {
  419. name_len.* = readComm(pid, name_out);
  420. return pid;
  421. }
  422. }
  423. }
  424. }
  425. /// Does this pid have that socket open? An unreadable `/proc/<pid>/fd` answers
  426. /// false — the process belongs to another user and is simply not visible.
  427. fn fdsHold(pid: u32, want_link: []const u8) bool {
  428. var path: [64:0]u8 = undefined;
  429. const dir_path = std.fmt.bufPrintZ(&path, "/proc/{d}/fd", .{pid}) catch return false;
  430. const dir_fd = sysOpen(dir_path, true) orelse return false;
  431. defer sysClose(dir_fd);
  432. var ents: [4096]u8 align(8) = undefined;
  433. while (true) {
  434. const rc = lin.getdents64(dir_fd, &ents, ents.len);
  435. const got: i64 = @bitCast(@as(u64, rc));
  436. if (got <= 0) return false;
  437. var off: usize = 0;
  438. while (off < @as(usize, @intCast(got))) {
  439. const ent: *align(1) const lin.dirent64 = @ptrCast(&ents[off]);
  440. off += ent.reclen;
  441. const name_ptr: [*:0]const u8 = @ptrCast(&ent.name);
  442. var lbuf: [64]u8 = undefined;
  443. const lrc = lin.readlinkat(dir_fd, name_ptr, &lbuf, lbuf.len);
  444. const llen: i64 = @bitCast(@as(u64, lrc));
  445. if (llen <= 0) continue;
  446. if (std.mem.eql(u8, lbuf[0..@intCast(llen)], want_link)) return true;
  447. }
  448. }
  449. }
  450. fn readComm(pid: u32, out: []u8) usize {
  451. var path: [64:0]u8 = undefined;
  452. const p = std.fmt.bufPrintZ(&path, "/proc/{d}/comm", .{pid}) catch return 0;
  453. const fd = sysOpen(p, false) orelse return 0;
  454. defer sysClose(fd);
  455. const rc = lin.read(fd, out.ptr, out.len);
  456. const got: i64 = @bitCast(@as(u64, rc));
  457. if (got <= 0) return 0;
  458. var len: usize = @intCast(got);
  459. while (len > 0 and (out[len - 1] == '\n' or out[len - 1] == '\r')) len -= 1;
  460. return len;
  461. }
  462. /// The sentence a transport appends to `bind() failed on port N`. It never fails: a
  463. /// buffer too small or a `/proc` that will not answer degrades to the part that IS
  464. /// known, and the errno alone already says more than the old message did.
  465. pub fn bindFailureDetail(out: []u8, rc: usize, port: u16, udp: bool) []const u8 {
  466. const signed: i64 = @bitCast(@as(u64, rc));
  467. const errno: u32 = if (signed < 0 and signed > -4096) @intCast(-signed) else 0;
  468. var w: usize = 0;
  469. const head = std.fmt.bufPrint(out[w..], "{s} — {s}", .{ errnoWord(errno), errnoWhy(errno) }) catch return out[0..w];
  470. w += head.len;
  471. if (errno != 98) return out[0..w];
  472. const sock = socketOnPort(port, udp) orelse {
  473. const gone = std.fmt.bufPrint(out[w..], "; nothing holds it now — the listener came and went", .{}) catch return out[0..w];
  474. return out[0 .. w + gone.len];
  475. };
  476. var abuf: [80]u8 = undefined;
  477. const addr = writeProcAddr(&abuf, sock.addr_hex[0..sock.addr_len], port);
  478. var comm: [32]u8 = undefined;
  479. var comm_len: usize = 0;
  480. if (pidHolding(sock.inode, &comm, &comm_len)) |pid| {
  481. const tail = std.fmt.bufPrint(out[w..], "; held by pid {d} ({s}) on {s}", .{ pid, comm[0..comm_len], addr }) catch return out[0..w];
  482. return out[0 .. w + tail.len];
  483. }
  484. const tail = std.fmt.bufPrint(out[w..], "; held on {s} by a process this one cannot see (another user)", .{addr}) catch return out[0..w];
  485. return out[0 .. w + tail.len];
  486. }

Branches

Latest commits

  • 10f8a8c8Merge branch 'code-order' into mainJukebox
  • 204fc828Merge branch 'day72' into mainJukebox
  • 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
  • 33072bb5|||PR Record day72 gates and Chrome proofmre
  • 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
  • 6422a020Sync media-player at 51c3818mre
  • b582ba1cVendor complete Hybriel day72 plugin setmre
  • 02dccbc9Merge branch 'records-1119' into mainJukebox
  • a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
  • fc7db075Merge branch 'reconnect-retry' into mainJukebox
  • ac6f4c6fL2: plain declaration for a in pickedNextmre
  • 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
  • 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
  • 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
  • 1f0cd77bMerge branch 'records-day41' into mainJukebox
  • 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
  • 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
  • 04f5d9d5Merge branch 'day41' into mainJukebox
  • 8ed6da45|||PR README: media-player pin df9e7dfmre
  • d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre