Bound engineering UI state and session events for M9.8b
This commit is contained in:
@@ -31,6 +31,7 @@ struct SessionClient::Impl {
|
||||
client::EnvironmentLayer environment;
|
||||
client::OrganismLayer organisms;
|
||||
std::vector<ClientEvent> events;
|
||||
bool awaiting_event_drain{};
|
||||
|
||||
void disconnect(Clock::time_point now, std::optional<CloseReason> reason) {
|
||||
if (step == Step::established || step == Step::awaiting_welcome || reason)
|
||||
@@ -87,6 +88,13 @@ struct SessionClient::Impl {
|
||||
return true;
|
||||
}
|
||||
bool frame(const OwnedFrame& f, Clock::time_point now) {
|
||||
// Reserve loss + backpressure + every unresolved intention; never evict an event.
|
||||
if (events.size() >= max_events - max_outstanding - 2) {
|
||||
events.push_back({ClientEvent::Kind::backpressure, {}, {}, {}, {}, 0});
|
||||
awaiting_event_drain = true;
|
||||
disconnect(now, std::nullopt);
|
||||
return false;
|
||||
}
|
||||
const FrameView v{f.type, f.payload};
|
||||
last_received = now;
|
||||
if (step == Step::awaiting_welcome) {
|
||||
@@ -225,8 +233,14 @@ SessionClient::create(SessionClientConfig config) {
|
||||
void SessionClient::poll(std::chrono::steady_clock::time_point now) {
|
||||
auto& m = *impl_;
|
||||
m.polled_at = now;
|
||||
if (m.phase == SessionPhase::exhausted)
|
||||
if (m.awaiting_event_drain || m.phase == SessionPhase::exhausted)
|
||||
return;
|
||||
if (m.events.size() >= max_events - max_outstanding - 2) {
|
||||
m.events.push_back({ClientEvent::Kind::backpressure, {}, {}, {}, {}, 0});
|
||||
m.awaiting_event_drain = true;
|
||||
m.disconnect(now, std::nullopt);
|
||||
return;
|
||||
}
|
||||
if (m.phase == SessionPhase::backoff) {
|
||||
if (now < m.retry_at)
|
||||
return;
|
||||
@@ -314,6 +328,7 @@ std::size_t SessionClient::grants_left() const noexcept {
|
||||
return impl_->config.grants.size() - impl_->next_grant;
|
||||
}
|
||||
std::vector<ClientEvent> SessionClient::take_events() {
|
||||
impl_->awaiting_event_drain = false;
|
||||
return std::exchange(impl_->events, {});
|
||||
}
|
||||
} // namespace evo::network
|
||||
|
||||
Reference in New Issue
Block a user