Skip to content

Commit

Permalink
remove unused file.
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeshadow committed Apr 2, 2024
1 parent eb4aba3 commit 321a35e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 101 deletions.
88 changes: 35 additions & 53 deletions postgres/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use core::{
pin::Pin,
};

use std::net::SocketAddr;

use postgres_protocol::message::backend;
use xitca_io::{
bytes::BytesMut,
Expand Down Expand Up @@ -87,24 +85,26 @@ pub struct Driver {
}

impl Driver {
// run till the connection is closed by Client.
async fn run_till_closed(self) {
let _ = match self.inner {
_Driver::Tcp(drv) => drv.run().await,
_Driver::Dynamic(drv) => drv.run().await,
#[cfg(feature = "tls")]
_Driver::Tls(drv) => drv.run().await,
#[cfg(unix)]
_Driver::Unix(drv) => drv.run().await,
#[cfg(all(unix, feature = "tls"))]
_Driver::UnixTls(drv) => drv.run().await,
#[cfg(feature = "quic")]
_Driver::Quic(drv) => drv.run().await,
};
#[cfg(feature = "io-uring")]
/// downcast [Driver] to IoUringDriver if it's Tcp variant.
/// IoUringDriver can not be a new variant of Dirver as it's !Send.
pub fn try_into_io_uring_tcp(self) -> io_uring::IoUringDriver<xitca_io::net::io_uring::TcpStream> {
match self.inner {
_Driver::Tcp(drv) => {
let std = drv.io.into_std().unwrap();
let tcp = xitca_io::net::io_uring::TcpStream::from_std(std);
io_uring::IoUringDriver::new(
tcp,
drv.state.take_rx(),
drv.write_buf.into_inner(),
drv.read_buf.into_inner(),
drv.res,
)
}
_ => todo!(),
}
}
}

impl Driver {
pub(super) fn tcp(drv: GenericDriver<TcpStream>) -> Self {
Self {
inner: _Driver::Tcp(drv),
Expand Down Expand Up @@ -144,7 +144,24 @@ impl Driver {
inner: _Driver::Quic(drv),
}
}

// run till the connection is closed by Client.
async fn run_till_closed(self) {
let _ = match self.inner {
_Driver::Tcp(drv) => drv.run().await,
_Driver::Dynamic(drv) => drv.run().await,
#[cfg(feature = "tls")]
_Driver::Tls(drv) => drv.run().await,
#[cfg(unix)]
_Driver::Unix(drv) => drv.run().await,
#[cfg(all(unix, feature = "tls"))]
_Driver::UnixTls(drv) => drv.run().await,
#[cfg(feature = "quic")]
_Driver::Quic(drv) => drv.run().await,
};
}
}

// TODO: use Box<dyn AsyncIterator> when life time GAT is object safe.
enum _Driver {
Tcp(GenericDriver<TcpStream>),
Expand Down Expand Up @@ -189,41 +206,6 @@ impl IntoFuture for Driver {
}
}

async fn resolve(host: &str, ports: &[u16]) -> Result<Vec<SocketAddr>, Error> {
let addrs = tokio::net::lookup_host((host, 0))
.await?
.flat_map(|mut addr| {
ports.iter().map(move |port| {
addr.set_port(*port);
addr
})
})
.collect::<Vec<_>>();
Ok(addrs)
}

#[cfg(feature = "io-uring")]
impl Driver {
// downcast Driver to IoUringDriver if it's Tcp variant.
// IoUringDriver can not be a new variant of Dirver as it's !Send.
pub fn try_into_io_uring_tcp(self) -> io_uring::IoUringDriver<xitca_io::net::io_uring::TcpStream> {
match self.inner {
_Driver::Tcp(drv) => {
let std = drv.io.into_std().unwrap();
let tcp = xitca_io::net::io_uring::TcpStream::from_std(std);
io_uring::IoUringDriver::new(
tcp,
drv.state.take_rx(),
drv.write_buf.into_inner(),
drv.read_buf.into_inner(),
drv.res,
)
}
_ => todo!(),
}
}
}

pub(crate) trait Drive: Send {
fn send(&mut self, msg: BytesMut) -> impl Future<Output = Result<(), Error>> + Send;

Expand Down
19 changes: 15 additions & 4 deletions postgres/src/driver/connect.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! tcp socket client.
use std::io;
use std::{io, net::SocketAddr};

use postgres_protocol::message::frontend;
use xitca_io::{
Expand Down Expand Up @@ -96,7 +94,7 @@ where
}

async fn connect_tcp(host: &str, ports: &[u16]) -> Result<TcpStream, Error> {
let addrs = super::resolve(host, ports).await?;
let addrs = resolve(host, ports).await?;

let mut err = None;

Expand Down Expand Up @@ -154,3 +152,16 @@ where
}
}
}

pub(super) async fn resolve(host: &str, ports: &[u16]) -> Result<Vec<SocketAddr>, Error> {
let addrs = tokio::net::lookup_host((host, 0))
.await?
.flat_map(|mut addr| {
ports.iter().map(move |port| {
addr.set_port(*port);
addr
})
})
.collect::<Vec<_>>();
Ok(addrs)
}
2 changes: 1 addition & 1 deletion postgres/src/driver/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ fn dangerous_config_rustls_0dot21(alpn: Vec<Vec<u8>>) -> Arc<rustls_0dot21::Clie
#[cold]
#[inline(never)]
pub(crate) async fn connect_quic(host: &str, ports: &[u16]) -> Result<QuicStream, Error> {
let addrs = super::resolve(host, ports).await?;
let addrs = super::connect::resolve(host, ports).await?;
let mut endpoint = Endpoint::client("0.0.0.0:0".parse().unwrap())?;

let cfg = dangerous_config_rustls_0dot21(vec![QUIC_ALPN.to_vec()]);
Expand Down
43 changes: 0 additions & 43 deletions postgres/src/driver/response.rs

This file was deleted.

0 comments on commit 321a35e

Please sign in to comment.