lib: Make CMSession users poll the context
This commit is contained in:
parent
5e7d4c6d98
commit
f05f8315cb
|
@ -22,7 +22,9 @@ pub async fn main() -> eyre::Result<()> {
|
|||
let servers = vapore::selection::bootstrap_find_servers().await?;
|
||||
log::debug!("Found servers: {:?}", servers);
|
||||
|
||||
let session = vapore::connection::CMSession::connect(&servers[0]).await?;
|
||||
let (session, context) = vapore::connection::CMSession::connect(&servers[0]).await?;
|
||||
|
||||
tokio::spawn(context);
|
||||
|
||||
session.send_notification(
|
||||
EMsg::k_EMsgClientHello,
|
||||
|
|
|
@ -30,7 +30,9 @@ pub async fn main() -> eyre::Result<()> {
|
|||
let servers = vapore::selection::bootstrap_find_servers().await?;
|
||||
log::debug!("Found servers: {:?}", servers);
|
||||
|
||||
let session = CMSession::connect(&servers[0]).await?;
|
||||
let (session, context) = CMSession::connect(&servers[0]).await?;
|
||||
|
||||
tokio::spawn(context);
|
||||
|
||||
session.send_notification(
|
||||
EMsg::k_EMsgClientHello,
|
||||
|
|
|
@ -71,7 +71,12 @@ impl CMSessionInner {
|
|||
}
|
||||
}
|
||||
|
||||
struct CMContext {
|
||||
/// Task to manage a single Connection Manager socket.
|
||||
/// Functions on the matching [CMSession] objects will use this Context
|
||||
/// to send and recieve messages.
|
||||
/// Users _must_ poll this to make any progress, e.g. with `tokio::spawn(context)`
|
||||
#[must_use = "Messages will not be sent or received unless context is polled"]
|
||||
pub struct CMContext {
|
||||
socket: WebSocketStream<ConnectStream>,
|
||||
session: Arc<Mutex<CMSessionInner>>,
|
||||
}
|
||||
|
@ -204,7 +209,8 @@ pub struct CMSession {
|
|||
}
|
||||
|
||||
impl CMSession {
|
||||
pub async fn connect(server: &str) -> Result<Self, ClientError> {
|
||||
/// Connect to a given Steam Connection Manager server
|
||||
pub async fn connect(server: &str) -> Result<(Self, CMContext), ClientError> {
|
||||
let (socket, _) = connect_async(server)
|
||||
.await
|
||||
.with_context(|_| WebSocketConnectSnafu {
|
||||
|
@ -229,13 +235,11 @@ impl CMSession {
|
|||
session: inner_wrapped.clone(),
|
||||
};
|
||||
|
||||
tokio::spawn(context);
|
||||
|
||||
let session = Self {
|
||||
inner: inner_wrapped,
|
||||
};
|
||||
|
||||
Ok(session)
|
||||
Ok((session, context))
|
||||
}
|
||||
|
||||
pub fn begin_heartbeat(&self, interval: u32) {
|
||||
|
|
Loading…
Reference in a new issue