Skip to content

Commit 564e885

Browse files
committed
fix!: enable async I/O code independent of blocking_io
1 parent 9de190e commit 564e885

File tree

9 files changed

+43
-42
lines changed

9 files changed

+43
-42
lines changed

gix-protocol/tests/protocol/fetch/arguments.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ use bstr::ByteSlice;
22
use gix_transport::Protocol;
33

44
use crate::fetch;
5+
#[cfg(feature = "async-client")]
6+
use gix_transport::client::git::async_io::Connection;
7+
#[cfg(feature = "blocking-client")]
8+
use gix_transport::client::git::blocking_io::Connection;
59

610
fn arguments_v1(features: impl IntoIterator<Item = &'static str>) -> fetch::Arguments {
711
fetch::Arguments::new(Protocol::V1, features.into_iter().map(|n| (n, None)).collect(), false)
@@ -140,12 +144,9 @@ mod impls {
140144
}
141145
}
142146

143-
fn transport(
144-
out: &mut Vec<u8>,
145-
stateful: bool,
146-
) -> Transport<gix_transport::client::git::Connection<&'static [u8], &mut Vec<u8>>> {
147+
fn transport(out: &mut Vec<u8>, stateful: bool) -> Transport<Connection<&'static [u8], &mut Vec<u8>>> {
147148
Transport {
148-
inner: gix_transport::client::git::Connection::new(
149+
inner: Connection::new(
149150
&[],
150151
out,
151152
Protocol::V1, // does not matter

gix-protocol/tests/protocol/fetch/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ pub fn transport<W: futures_io::AsyncWrite + Unpin>(
302302
path: &str,
303303
desired_version: gix_transport::Protocol,
304304
mode: gix_transport::client::git::ConnectMode,
305-
) -> gix_transport::client::git::Connection<Cursor, W> {
305+
) -> gix_transport::client::git::async_io::Connection<Cursor, W> {
306306
let response = fixture_bytes(path);
307-
gix_transport::client::git::Connection::new(
307+
gix_transport::client::git::async_io::Connection::new(
308308
Cursor::new(response),
309309
out,
310310
desired_version,
@@ -321,9 +321,9 @@ pub fn transport<W: std::io::Write>(
321321
path: &str,
322322
version: gix_transport::Protocol,
323323
mode: gix_transport::client::git::ConnectMode,
324-
) -> gix_transport::client::git::Connection<Cursor, W> {
324+
) -> gix_transport::client::git::blocking_io::Connection<Cursor, W> {
325325
let response = fixture_bytes(path);
326-
gix_transport::client::git::Connection::new(
326+
gix_transport::client::git::blocking_io::Connection::new(
327327
Cursor::new(response),
328328
out,
329329
version,

gix-transport/src/client/async_io/connect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub use crate::client::non_io_types::connect::{Error, Options};
22

33
#[cfg(feature = "async-std")]
44
pub(crate) mod function {
5-
use crate::client::{async_io::Transport, git, non_io_types::connect::Error};
5+
use crate::client::{async_io::Transport, git::async_io::Connection, non_io_types::connect::Error};
66

77
/// A general purpose connector connecting to a repository identified by the given `url`.
88
///
@@ -26,7 +26,7 @@ pub(crate) mod function {
2626
}
2727
let path = std::mem::take(&mut url.path);
2828
Box::new(
29-
git::Connection::new_tcp(
29+
Connection::new_tcp(
3030
url.host().expect("host is present in url"),
3131
url.port,
3232
path,

gix-transport/src/client/blocking_io/http/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ use crate::{
1919
http::options::{HttpVersion, SslVersionRangeInclusive},
2020
ExtendedBufRead, HandleProgress, RequestWriter, SetServiceResponse,
2121
},
22-
capabilities, Capabilities, MessageKind,
22+
capabilities::blocking_recv::Outcome,
23+
MessageKind,
2324
},
2425
packetline::{blocking_io::StreamingPeekableIter, PacketLineRef},
2526
Protocol, Service,
@@ -402,11 +403,11 @@ impl<H: Http> blocking_io::Transport for Transport<H> {
402403
line_reader.as_read().read_to_end(&mut Vec::new())?;
403404
}
404405

405-
let capabilities::recv::Outcome {
406+
let Outcome {
406407
capabilities,
407408
refs,
408409
protocol: actual_protocol,
409-
} = Capabilities::from_lines_with_version_detection(line_reader)?;
410+
} = Outcome::from_lines_with_version_detection(line_reader)?;
410411
self.actual_version = actual_protocol;
411412
self.service = Some(service);
412413
Ok(SetServiceResponse {

gix-transport/src/client/capabilities.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl Capabilities {
167167

168168
#[cfg(feature = "blocking-client")]
169169
///
170-
pub mod recv {
170+
pub mod blocking_recv {
171171
use std::io;
172172

173173
use bstr::ByteVec;
@@ -178,7 +178,7 @@ pub mod recv {
178178
Protocol,
179179
};
180180

181-
/// Success outcome of [`Capabilities::from_lines_with_version_detection`].
181+
/// Success outcome of [`Outcome::from_lines_with_version_detection`].
182182
pub struct Outcome<'a> {
183183
/// The [`Capabilities`] the remote advertised.
184184
pub capabilities: Capabilities,
@@ -191,7 +191,7 @@ pub mod recv {
191191
pub protocol: Protocol,
192192
}
193193

194-
impl Capabilities {
194+
impl Outcome<'_> {
195195
/// Read the capabilities and version advertisement from the given packetline reader.
196196
///
197197
/// If [`Protocol::V1`] was requested, or the remote decided to downgrade, the remote refs
@@ -253,10 +253,10 @@ pub mod recv {
253253
}
254254
}
255255

256-
#[cfg(all(feature = "async-client", not(feature = "blocking-client")))]
256+
#[cfg(feature = "async-client")]
257257
#[allow(missing_docs)]
258258
///
259-
pub mod recv {
259+
pub mod async_recv {
260260
use bstr::ByteVec;
261261
use futures_io::AsyncRead;
262262

@@ -266,7 +266,7 @@ pub mod recv {
266266
Protocol,
267267
};
268268

269-
/// Success outcome of [`Capabilities::from_lines_with_version_detection`].
269+
/// Success outcome of [`Outcome::from_lines_with_version_detection`].
270270
pub struct Outcome<'a> {
271271
/// The [`Capabilities`] the remote advertised.
272272
pub capabilities: Capabilities,
@@ -279,7 +279,7 @@ pub mod recv {
279279
pub protocol: Protocol,
280280
}
281281

282-
impl Capabilities {
282+
impl Outcome<'_> {
283283
/// Read the capabilities and version advertisement from the given packetline reader.
284284
///
285285
/// If [`Protocol::V1`] was requested, or the remote decided to downgrade, the remote refs

gix-transport/src/client/git/async_io.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ use crate::{
99
client::{
1010
self,
1111
async_io::{RequestWriter, SetServiceResponse},
12-
capabilities,
12+
capabilities::async_recv::Outcome,
1313
git::{self, ConnectionState},
14-
Capabilities,
1514
},
1615
packetline::{
1716
async_io::{StreamingPeekableIter, Writer},
@@ -97,11 +96,11 @@ where
9796
line_writer.flush().await?;
9897
}
9998

100-
let capabilities::recv::Outcome {
99+
let Outcome {
101100
capabilities,
102101
refs,
103102
protocol: actual_protocol,
104-
} = Capabilities::from_lines_with_version_detection(&mut self.line_provider).await?;
103+
} = Outcome::from_lines_with_version_detection(&mut self.line_provider).await?;
105104
Ok(SetServiceResponse {
106105
actual_protocol,
107106
capabilities,
@@ -164,9 +163,12 @@ mod async_net {
164163

165164
use async_std::net::TcpStream;
166165

167-
use crate::client::{git, Error};
166+
use crate::client::{
167+
git::{async_io::Connection, ConnectMode},
168+
Error,
169+
};
168170

169-
impl git::Connection<TcpStream, TcpStream> {
171+
impl Connection<TcpStream, TcpStream> {
170172
/// Create a new TCP connection using the `git` protocol of `desired_version`, and make a connection to `host`
171173
/// at `port` for accessing the repository at `path` on the server side.
172174
/// If `trace` is `true`, all packetlines received or sent will be passed to the facilities of the `gix-trace` crate.
@@ -176,20 +178,20 @@ mod async_net {
176178
path: bstr::BString,
177179
desired_version: crate::Protocol,
178180
trace: bool,
179-
) -> Result<git::Connection<TcpStream, TcpStream>, Error> {
181+
) -> Result<Self, Error> {
180182
let read = async_std::io::timeout(
181183
Duration::from_secs(5),
182184
TcpStream::connect(&(host, port.unwrap_or(9418))),
183185
)
184186
.await?;
185187
let write = read.clone();
186-
Ok(git::Connection::new(
188+
Ok(Self::new(
187189
read,
188190
write,
189191
desired_version,
190192
path,
191193
None::<(String, _)>,
192-
git::ConnectMode::Daemon,
194+
ConnectMode::Daemon,
193195
trace,
194196
))
195197
}

gix-transport/src/client/git/blocking_io.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use crate::{
66
client::{
77
self,
88
blocking_io::{RequestWriter, SetServiceResponse},
9-
capabilities,
9+
capabilities::blocking_recv::Outcome,
1010
git::{self, ConnectionState},
11-
Capabilities,
1211
},
1312
packetline::{
1413
blocking_io::{StreamingPeekableIter, Writer},
@@ -92,11 +91,11 @@ where
9291
line_writer.flush()?;
9392
}
9493

95-
let capabilities::recv::Outcome {
94+
let Outcome {
9695
capabilities,
9796
refs,
9897
protocol: actual_protocol,
99-
} = Capabilities::from_lines_with_version_detection(&mut self.line_provider)?;
98+
} = Outcome::from_lines_with_version_detection(&mut self.line_provider)?;
10099
Ok(SetServiceResponse {
101100
actual_protocol,
102101
capabilities,

gix-transport/src/client/git/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,10 @@ mod message {
161161
}
162162
}
163163

164-
#[cfg(all(feature = "async-client", not(feature = "blocking-client")))]
165-
pub(crate) mod async_io;
166-
#[cfg(all(feature = "async-client", not(feature = "blocking-client")))]
167-
pub use async_io::Connection;
164+
///
165+
#[cfg(feature = "async-client")]
166+
pub mod async_io;
168167

168+
///
169169
#[cfg(feature = "blocking-client")]
170-
pub(crate) mod blocking_io;
171-
#[cfg(feature = "blocking-client")]
172-
pub use blocking_io::{connect, Connection};
170+
pub mod blocking_io;

gix-transport/src/client/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///
2-
#[cfg(all(feature = "async-client", not(feature = "blocking-client")))]
2+
#[cfg(feature = "async-client")]
33
pub mod async_io;
44

55
mod traits;

0 commit comments

Comments
 (0)