summaryrefslogtreecommitdiff
path: root/src/verbs.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 00:59:14 -0300
committerGabriel Schneider <[email protected]>2026-11-17 10:06:26 -0300
commit7f418a6bb3c2d5319d781a61a14aeaf15aff4c89 (patch)
tree6b3324331fe2e4ed195e4864eca8362d4137b9bf /src/verbs.zig
parentb44d970c121a65e1f9de04fee600a3b495fb6c96 (diff)
downloadcloud9-7f418a6bb3c2d5319d781a61a14aeaf15aff4c89.tar.gz
cloud9-7f418a6bb3c2d5319d781a61a14aeaf15aff4c89.zip
Fsys: a deadline on every call, so a silent server is a timeout
A server that accepted and then said nothing held the caller for ever: Fsys read its socket with no limit, the version in init included, while pardes's own client gives a call 2 s and a write that runs a command 30 s. Fsys gains one field, `timeout` (an Io.Timeout), which init sets to `default_timeout`, 30 s, before it speaks; each call's answer is read by operateTimeout until that long after the call is sent, and past it the call is error.Timeout (the answer may come yet, under a tag the next call does not expect, so the connection is to be closed). `.none` waits for ever: verbs' follow sets it, since following an event file waits as long as the events take; read, ls, ask and the rest keep the deadline and say "no answer in 30000 ms; fs follow waits for ever". Test: a held read nobody feeds, on a 100 ms timeout, is error.Timeout after 90-5000 ms (poll counts whole milliseconds). cloud9's test 108 of 108; serve's "two clients at once" and "repeated connect/disconnect" failed once each at load 13 and passed in the four runs after, as on the base: they do not touch Fsys. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/verbs.zig')
-rw-r--r--src/verbs.zig4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/verbs.zig b/src/verbs.zig
index c9174d3..722a0c2 100644
--- a/src/verbs.zig
+++ b/src/verbs.zig
@@ -31,7 +31,7 @@ pub const usage =
\\ fs read PATH the file, to its end (a held read streams)
\\ fs write PATH [WORDS...] the words and a newline, else stdin, as > would
\\ fs ask PATH WORDS... write the words and read the answer on the same open
- \\ fs follow PATH [WORDS...] ask, or read: what comes, as it comes
+ \\ fs follow PATH [WORDS...] ask, or read: what comes, as it comes, for as long
\\ fs stat PATH mode length uid gid mtime name
\\ fs help [PATH] what the tree's README says of PATH
\\ fs complete [PREFIX] the paths that go on from PREFIX, for a shell
@@ -49,6 +49,7 @@ pub fn run(f: *Fsys, args: []const []const u8, in: *Io.Reader, out: *Io.Writer,
error.Refused => err.print("fs: {s}: {s}\n", .{ path, f.said() }),
error.Hangup => err.print("fs: {s}: the server hung up\n", .{path}),
error.Botch => err.print("fs: {s}: protocol botch\n", .{path}),
+ error.Timeout => err.print("fs: {s}: no answer in {d} ms; fs follow waits for ever\n", .{ path, if (f.timeout.toDurationFromNow(f.io)) |d| d.raw.toMilliseconds() else 0 }),
error.Usage => err.writeAll(usage),
error.TooLong => err.print("fs: {s}: the words are longer than a message\n", .{path}),
// Our own stdin or stdout: nothing to say it on.
@@ -106,6 +107,7 @@ fn runVerb(f: *Fsys, args: []const []const u8, in: *Io.Reader, out: *Io.Writer,
},
.follow => {
if (args.len < 2) return error.Usage;
+ f.timeout = .none;
if (words.len == 0) try f.readFile(path, out) else try f.ask(path, try line(&line_buf, words), out);
},
.stat => {