mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-28 21:32:39 +00:00
Add a generic Ack
message, use it instead of Pong
Remove the `id` field from `Ping`, because it isn't used. There is already an id on the message envelope.
This commit is contained in:
parent
000305472a
commit
38bfaba135
5 changed files with 17 additions and 40 deletions
|
@ -246,14 +246,7 @@ impl Server {
|
|||
}
|
||||
|
||||
async fn ping(self: Arc<Server>, request: TypedEnvelope<proto::Ping>) -> tide::Result<()> {
|
||||
self.peer
|
||||
.respond(
|
||||
request.receipt(),
|
||||
proto::Pong {
|
||||
id: request.payload.id,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
self.peer.respond(request.receipt(), proto::Ack {}).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -139,13 +139,9 @@ impl Client {
|
|||
let this = self.clone();
|
||||
let foreground = cx.foreground();
|
||||
state._maintain_connection = Some(cx.foreground().spawn(async move {
|
||||
let mut next_ping_id = 0;
|
||||
loop {
|
||||
foreground.timer(heartbeat_interval).await;
|
||||
this.request(proto::Ping { id: next_ping_id })
|
||||
.await
|
||||
.unwrap();
|
||||
next_ping_id += 1;
|
||||
this.request(proto::Ping {}).await.unwrap();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -543,13 +539,11 @@ mod tests {
|
|||
|
||||
cx.foreground().advance_clock(Duration::from_secs(10));
|
||||
let ping = server.receive::<proto::Ping>().await.unwrap();
|
||||
assert_eq!(ping.payload.id, 0);
|
||||
server.respond(ping.receipt(), proto::Pong { id: 0 }).await;
|
||||
server.respond(ping.receipt(), proto::Ack {}).await;
|
||||
|
||||
cx.foreground().advance_clock(Duration::from_secs(10));
|
||||
let ping = server.receive::<proto::Ping>().await.unwrap();
|
||||
assert_eq!(ping.payload.id, 1);
|
||||
server.respond(ping.receipt(), proto::Pong { id: 1 }).await;
|
||||
server.respond(ping.receipt(), proto::Ack {}).await;
|
||||
|
||||
client.disconnect(&cx.to_async()).await.unwrap();
|
||||
assert!(server.receive::<proto::Ping>().await.is_err());
|
||||
|
|
|
@ -6,9 +6,9 @@ message Envelope {
|
|||
optional uint32 responding_to = 2;
|
||||
optional uint32 original_sender_id = 3;
|
||||
oneof payload {
|
||||
Error error = 4;
|
||||
Ping ping = 5;
|
||||
Pong pong = 6;
|
||||
Ack ack = 4;
|
||||
Error error = 5;
|
||||
Ping ping = 6;
|
||||
ShareWorktree share_worktree = 7;
|
||||
ShareWorktreeResponse share_worktree_response = 8;
|
||||
OpenWorktree open_worktree = 9;
|
||||
|
@ -40,13 +40,9 @@ message Envelope {
|
|||
|
||||
// Messages
|
||||
|
||||
message Ping {
|
||||
int32 id = 1;
|
||||
}
|
||||
message Ping {}
|
||||
|
||||
message Pong {
|
||||
int32 id = 2;
|
||||
}
|
||||
message Ack {}
|
||||
|
||||
message Error {
|
||||
string message = 1;
|
||||
|
|
|
@ -371,18 +371,18 @@ mod tests {
|
|||
|
||||
assert_eq!(
|
||||
client1
|
||||
.request(client1_conn_id, proto::Ping { id: 1 },)
|
||||
.request(client1_conn_id, proto::Ping {},)
|
||||
.await
|
||||
.unwrap(),
|
||||
proto::Pong { id: 1 }
|
||||
proto::Ack {}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
client2
|
||||
.request(client2_conn_id, proto::Ping { id: 2 },)
|
||||
.request(client2_conn_id, proto::Ping {},)
|
||||
.await
|
||||
.unwrap(),
|
||||
proto::Pong { id: 2 }
|
||||
proto::Ack {}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
|
@ -438,13 +438,7 @@ mod tests {
|
|||
let envelope = envelope.into_any();
|
||||
if let Some(envelope) = envelope.downcast_ref::<TypedEnvelope<proto::Ping>>() {
|
||||
let receipt = envelope.receipt();
|
||||
peer.respond(
|
||||
receipt,
|
||||
proto::Pong {
|
||||
id: envelope.payload.id,
|
||||
},
|
||||
)
|
||||
.await?
|
||||
peer.respond(receipt, proto::Ack {}).await?
|
||||
} else if let Some(envelope) =
|
||||
envelope.downcast_ref::<TypedEnvelope<proto::OpenBuffer>>()
|
||||
{
|
||||
|
@ -536,7 +530,7 @@ mod tests {
|
|||
smol::spawn(async move { incoming.next().await }).detach();
|
||||
|
||||
let err = client
|
||||
.request(connection_id, proto::Ping { id: 42 })
|
||||
.request(connection_id, proto::Ping {})
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert_eq!(err.to_string(), "connection was closed");
|
||||
|
|
|
@ -120,6 +120,7 @@ macro_rules! entity_messages {
|
|||
}
|
||||
|
||||
messages!(
|
||||
Ack,
|
||||
AddPeer,
|
||||
BufferSaved,
|
||||
ChannelMessageSent,
|
||||
|
@ -140,7 +141,6 @@ messages!(
|
|||
OpenWorktree,
|
||||
OpenWorktreeResponse,
|
||||
Ping,
|
||||
Pong,
|
||||
RemovePeer,
|
||||
SaveBuffer,
|
||||
SendChannelMessage,
|
||||
|
@ -157,7 +157,7 @@ request_messages!(
|
|||
(JoinChannel, JoinChannelResponse),
|
||||
(OpenBuffer, OpenBufferResponse),
|
||||
(OpenWorktree, OpenWorktreeResponse),
|
||||
(Ping, Pong),
|
||||
(Ping, Ack),
|
||||
(SaveBuffer, BufferSaved),
|
||||
(ShareWorktree, ShareWorktreeResponse),
|
||||
(SendChannelMessage, SendChannelMessageResponse),
|
||||
|
|
Loading…
Reference in a new issue