milestone 18: collapse duplicated infrastructure into shared listener core, crud list helper, resource shells, transport race, name and line helpers, ui modules
This commit is contained in:
+6
-59
@@ -181,28 +181,10 @@ pub const Pool = struct {
|
||||
query: []const u8,
|
||||
response_buf: []u8,
|
||||
) transport.ExchangeError![]u8 {
|
||||
var outcomes: [2]LoopOutcome = undefined;
|
||||
var race: std.Io.Select(LoopOutcome) = .init(io, &outcomes);
|
||||
defer race.cancelDiscard();
|
||||
|
||||
race.concurrent(.loop, exchangeLoopLen, .{
|
||||
const len = try transport.raceWithin(io, self.timeouts.total, exchangeLoopLen, .{
|
||||
self, io, query, response_buf,
|
||||
}) catch |err| switch (err) {
|
||||
error.ConcurrencyUnavailable => return error.SystemResources,
|
||||
};
|
||||
race.concurrent(.expiry, expire, .{ io, self.timeouts.total }) catch |err| switch (err) {
|
||||
error.ConcurrencyUnavailable => return error.SystemResources,
|
||||
};
|
||||
|
||||
switch (try race.await()) {
|
||||
.loop => |result| return response_buf[0..try result],
|
||||
.expiry => |result| {
|
||||
// A canceled sleep means this whole task is being torn down,
|
||||
// not that the budget ran out.
|
||||
try result;
|
||||
return error.Timeout;
|
||||
},
|
||||
}
|
||||
});
|
||||
return response_buf[0..len];
|
||||
}
|
||||
|
||||
/// The two-pass failover loop, as a raceable task. It returns the reply's
|
||||
@@ -300,9 +282,7 @@ pub const Pool = struct {
|
||||
return count;
|
||||
}
|
||||
|
||||
/// One exchange raced against the per-attempt budget. No stream read or
|
||||
/// write in 0.16.0 takes a timeout, so the budget is a second task and the
|
||||
/// loser is canceled.
|
||||
/// One exchange raced against the per-attempt budget.
|
||||
fn attempt(
|
||||
self: *Pool,
|
||||
io: std.Io,
|
||||
@@ -310,28 +290,9 @@ pub const Pool = struct {
|
||||
query: []const u8,
|
||||
response_buf: []u8,
|
||||
) transport.ExchangeError![]u8 {
|
||||
var outcomes: [2]Outcome = undefined;
|
||||
var race: std.Io.Select(Outcome) = .init(io, &outcomes);
|
||||
defer race.cancelDiscard();
|
||||
|
||||
race.concurrent(.exchange, transport.Client.exchange, .{
|
||||
return transport.raceWithin(io, self.timeouts.attempt, transport.Client.exchange, .{
|
||||
entry_client, io, query, response_buf,
|
||||
}) catch |err| switch (err) {
|
||||
error.ConcurrencyUnavailable => return error.SystemResources,
|
||||
};
|
||||
race.concurrent(.expiry, expire, .{ io, self.timeouts.attempt }) catch |err| switch (err) {
|
||||
error.ConcurrencyUnavailable => return error.SystemResources,
|
||||
};
|
||||
|
||||
switch (try race.await()) {
|
||||
.exchange => |result| return result,
|
||||
.expiry => |result| {
|
||||
// A canceled sleep means this whole task is being torn down,
|
||||
// not that the upstream is slow.
|
||||
try result;
|
||||
return error.Timeout;
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn entryAvailable(
|
||||
@@ -367,20 +328,6 @@ pub const Pool = struct {
|
||||
}
|
||||
};
|
||||
|
||||
const Outcome = union(enum) {
|
||||
exchange: transport.ExchangeError![]u8,
|
||||
expiry: std.Io.Cancelable!void,
|
||||
};
|
||||
|
||||
const LoopOutcome = union(enum) {
|
||||
loop: transport.ExchangeError!usize,
|
||||
expiry: std.Io.Cancelable!void,
|
||||
};
|
||||
|
||||
fn expire(io: std.Io, duration: std.Io.Clock.Duration) std.Io.Cancelable!void {
|
||||
return duration.sleep(io);
|
||||
}
|
||||
|
||||
const testing = std.testing;
|
||||
|
||||
/// A query for example.com A: id 0x1234, RD set, one question.
|
||||
|
||||
Reference in New Issue
Block a user