summaryrefslogtreecommitdiff
path: root/runtime/session.zig
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/session.zig')
-rw-r--r--runtime/session.zig72
1 files changed, 46 insertions, 26 deletions
diff --git a/runtime/session.zig b/runtime/session.zig
index f401c85a..fdd72c2b 100644
--- a/runtime/session.zig
+++ b/runtime/session.zig
@@ -2,29 +2,31 @@
//! (dev/gui `runNative`) alike, each with a frontend of its own. It holds
//! the session's allocators and workers, its core (an upgrade's, a dump's
//! or a new one), the prompt files its shells start with, its 9P listener
-//! and its replica clients (`Peers`): a step, its unit to the clients and
-//! theirs taken in, an Upgrade or a Restore between steps; and the order
-//! its parts end in. Its devices (the ptys and their readers, the files
-//! watched, the LSP's and the pipes' and addons' jobs, the queue they post
-//! to, the session's own input) are still its frontend's (each `Shell`,
-//! the services step's to make one). What a frontend does is:
+//! its replica clients (`Peers`), its queue (the workers' and readers'
+//! posts, `Inbox`), its ptys (`Ptys`) and the files it watches
+//! (`file_watch.Watches`): a step, its unit to the clients and theirs
+//! taken in, an Upgrade or a Restore between steps; and the order its
+//! parts end in. Its other devices (the LSP's and the pipes' and addons'
+//! jobs, the session's own input) are still its frontend's (each `Shell`);
+//! the language servers' answers come through its queue (`Inbox.startLsp`).
+//! What a frontend does is:
//!
//! - `options(o)`: before the core: what it gives the core it starts (a
//! window's size, for a dump's layout).
//! - `open(l) Host`: its devices made over the session's core and parts,
-//! the host the core steps with (the core's, set there); what it does
-//! before the core's first effects (an upgraded terminal's panes its
-//! own again, whether anyone looks).
+//! the host the core steps with (the core's, set there), who wakes it
+//! when the queue gets a post (`l.inbox`); what it does before the
+//! core's first effects (an upgraded terminal's panes its own again,
+//! whether anyone looks).
//! - `close(l)`: its devices stopped, after the clients are let go and
-//! before the core goes.
-//! - `resumePtys(rec)`: an upgraded session's shells, its own again.
-//! - `start(l)`: after the first effects: its input, its readers, the
-//! listener's wake, a detached session's first wait (`l.watch`).
+//! before the watches, the ptys, the queue and the core go.
+//! - `start(l)`: after the first effects, the ptys and the watches
+//! read: its input, its readers, the listener's wake, a detached
+//! session's first wait (`l.watch`).
//! - `sent()`: after each step's unit went to the clients.
//! - `upgradeAsked()`: an Upgrade asked in the step, done (it execs).
-//! - `note(n)`: what the daemon says (a terminal, an adopted shell, a
-//! client's connection), onto its queue.
-//! - `watched()`: the files it watches (a Restore stops watching them).
+//! - `note(n)`: what the daemon says (an adopted shell, a client's
+//! connection, a new daemon's hello taken), onto its queue.
//! - `restoring(nc)`, `restored(l)`: a Restore's new core, before it
//! replaces the old one (its devices let go, what it is told of the
//! frontend) and after (its own view of it again).
@@ -32,14 +34,12 @@ const std = @import("std");
const pardes = @import("core");
const replica = pardes.replica;
const host_io = @import("dev").host_io;
+const Ptys = host_io.Ptys;
const file_watch = @import("dev").file_watch;
const daemon = @import("daemon.zig");
const upgrade = @import("upgrade.zig");
const ninep_io = @import("9p_io.zig");
-/// The files a frontend watches (host_io.restoreCore lets them go).
-pub const Watched = struct { fd: c_int, table: *file_watch.Table };
-
pub fn Loop(comptime Frontend: type) type {
return struct {
const L = @This();
@@ -52,6 +52,11 @@ pub fn Loop(comptime Frontend: type) type {
frames: pardes.FrameStats = .{},
core: *pardes.Pardes = undefined,
prompt_rcs: host_io.Shell.PromptFiles = undefined,
+ /// What the session's workers and readers post, for the frontend
+ /// to take in its wait.
+ inbox: host_io.Inbox = undefined,
+ ptys: Ptys = undefined,
+ watches: file_watch.Watches = undefined,
fs: ?*ninep_io.Listener = null,
peers: replica.Peers = .{},
host: pardes.Host = undefined,
@@ -83,6 +88,15 @@ pub fn Loop(comptime Frontend: type) type {
l.fs = ninep_io.start(l.io, l.gpa, l.core);
defer if (l.fs) |f| f.deinit(l.gpa);
l.peers = .{ .gpa = l.gpa, .io = l.io, .name = daemon.name() };
+ l.inbox = .{ .io = l.io, .gpa = l.gpa, .lsp_allocator = l.allocs.lsp };
+ defer l.inbox.deinit();
+ // The language servers' status lines, from the first effects on.
+ pardes.lsp.setStatusSink(&l.inbox, host_io.Inbox.lspStatus);
+ defer pardes.lsp.setStatusSink(null, null);
+ l.ptys = .{ .queue = &l.inbox, .prompt_rcs = &l.prompt_rcs };
+ defer l.ptys.deinit();
+ l.watches = .open(l.io, l.gpa, &l.inbox);
+ defer l.watches.deinit();
l.host = try fe.open(&l);
defer fe.close(&l);
@@ -93,9 +107,11 @@ pub fn Loop(comptime Frontend: type) type {
// ...and its shells, once a fresh session's own has a directory
// to adopt them in.
if (upgrade.resumed) |*rec| {
- fe.resumePtys(rec);
+ l.ptys.resumeFrom(l.core, rec);
l.effects();
}
+ l.ptys.start(l.core);
+ l.watches.start();
try fe.start(&l);
while (!l.core.quit) {
@@ -108,8 +124,7 @@ pub fn Loop(comptime Frontend: type) type {
// Asked in the step (the word), done between steps: the
// session whole.
fe.upgradeAsked();
- // A terminal (`pardes --attach`), a window asked for again,
- // an adopted shell or a client's connection, handed on by
+ // An adopted shell or a client's connection, handed on by
// the daemon's thread; started after the first frame, off a
// start's way.
l.watch();
@@ -129,8 +144,10 @@ pub fn Loop(comptime Frontend: type) type {
}
/// What the daemon says, onto the frontend's queue (once: its
- /// reader is started by the first call).
+ /// reader is started by the first call); and a daemon started
+ /// since the last one died told the shells' masters it held.
pub fn watch(l: *L) void {
+ if (daemon.relinked()) l.ptys.tellDaemon();
daemon.watch(l.fe, note);
}
@@ -140,11 +157,14 @@ pub fn Loop(comptime Frontend: type) type {
}
/// A Restore: the core its dump makes replaces this one, its clients
- /// let go (host_io.restoreCore); the frontend's devices with it.
+ /// let go (host_io.restoreCore); its shells and the frontend's
+ /// devices with it.
fn restore(l: *L, path: []const u8) void {
- const w = l.fe.watched();
- const nc = host_io.restoreCore(l.gpa, l.core, path, &l.peers, w.fd, w.table) orelse return;
+ const nc = host_io.restoreCore(l.gpa, l.core, path, &l.peers, l.watches.fd, &l.watches.table) orelse return;
l.fe.restoring(nc);
+ // An answer to the old core's query is turned away.
+ l.inbox.discardCompletions();
+ l.ptys.stop();
nc.host = l.host;
if (l.fs) |f| f.reset(nc);
l.core.deinit();