Skip to content

Commit

Permalink
feat: provide a function to gracefully shut donw a fetch transport (#450
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Byron committed Aug 20, 2022
1 parent e2ee3de commit 5ba9e1d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
18 changes: 18 additions & 0 deletions git-protocol/src/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,23 @@ pub use response::Response;
pub mod handshake;
pub use handshake::function::handshake;

/// Send a message to indicate the remote side that there is nothing more to expect from us, indicating a graceful shutdown.
#[maybe_async::maybe_async]
pub async fn indicate_end_of_interaction(
mut transport: impl git_transport::client::Transport,
) -> Result<(), git_transport::client::Error> {
// An empty request marks the (early) end of the interaction. Only relevant in stateful transports though.
if transport.connection_persists_across_multiple_requests() {
transport
.request(
git_transport::client::WriteMode::Binary,
git_transport::client::MessageKind::Flush,
)?
.into_read()
.await?;
}
Ok(())
}

#[cfg(test)]
mod tests;
3 changes: 1 addition & 2 deletions git-protocol/src/fetch/refs/function.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::Error;
use crate::fetch::refs::from_v2_refs;
use crate::fetch::{Command, LsRefsAction, Ref};
use crate::fetch_fn::indicate_end_of_interaction;
use crate::fetch::{indicate_end_of_interaction, Command, LsRefsAction, Ref};
use bstr::BString;
use git_features::progress::Progress;
use git_transport::client::{Capabilities, Transport, TransportV2Ext};
Expand Down
16 changes: 1 addition & 15 deletions git-protocol/src/fetch_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use git_features::progress::Progress;
use git_transport::client;
use maybe_async::maybe_async;

use crate::fetch::handshake;
use crate::fetch::{handshake, indicate_end_of_interaction};
use crate::{
credentials,
fetch::{Action, Arguments, Command, Delegate, Error, Response},
Expand Down Expand Up @@ -142,20 +142,6 @@ where
Ok(())
}

#[maybe_async]
pub(crate) async fn indicate_end_of_interaction(
mut transport: impl client::Transport,
) -> Result<(), git_transport::client::Error> {
// An empty request marks the (early) end of the interaction. Only relevant in stateful transports though.
if transport.connection_persists_across_multiple_requests() {
transport
.request(client::WriteMode::Binary, client::MessageKind::Flush)?
.into_read()
.await?;
}
Ok(())
}

fn setup_remote_progress(
progress: &mut impl Progress,
reader: &mut Box<dyn git_transport::client::ExtendedBufRead + Unpin + '_>,
Expand Down

0 comments on commit 5ba9e1d

Please sign in to comment.