Skip to content

Commit 3e0434b

Browse files
authored
Make the Downstairs own per-connection state (#1328)
This PR moves ownership of the `ConnectionState` from a local variable in `proc_task` into the `struct Downstairs`. It is preparation for consolidating Downstairs logic into a single task, instead of the current task-per-connection architecture (in which multiple tasks share an `Arc<Mutex<Downstairs>>`). In the `Downstairs`, per-connection state is indexed by a new `ConnectionId` type, which is a monotonically increasing counter that increments on every new connection. We're using a new type because upstairs / session UUIDs are sometimes reused if a new connection is made, and we specifically _don't_ want to reuse `ConnectionState` between different connections to an upstairs with a maybe-matching UUID. In the previous code, this was ensured by using local variables in `proc_task` (which was spawned on a per-connection basis); now, we ensure it by using `ConnectionId` (which is also unique on a per-connection basis). This reorganization had a few other side effects: - Downstairs replacement is extracted from `proc_task` into `Downstairs::on_new_connection_replacing` (with minimal logical changes) - Message handling is extracted from `proc_task` into `Downstairs::on_message_for` (with minimal logical changes) - `proc_frame` now takes a `&mut Downstairs` (instead of a `Arc<Mutex<Downstairs>>`), because it is called from `on_message_for` (which already has the lock)
1 parent 3d97943 commit 3e0434b

File tree

1 file changed

+218
-184
lines changed

1 file changed

+218
-184
lines changed

0 commit comments

Comments
 (0)