Skip to content

Commit

Permalink
fix single thread feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeshadow committed Mar 6, 2024
1 parent ee493e6 commit 9c3257b
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 151 deletions.
2 changes: 1 addition & 1 deletion postgres/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(super) async fn connect(cfg: &mut Config) -> Result<(Client, Driver), Error>
let hosts = cfg.get_hosts().to_vec();
for host in hosts {
match _connect(host, cfg).await {
Ok(t) => return Ok(t),
Ok((tx, drv)) => return Ok((Client::new(tx), drv)),
Err(e) => err = Some(e),
}
}
Expand Down
9 changes: 4 additions & 5 deletions postgres/src/driver/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use quinn_proto::ConnectionError;
use xitca_io::bytes::{Bytes, BytesMut};

use crate::{
client::Client,
config::{Config, Host},
error::{unexpected_eof_err, Error},
iter::AsyncLendingIterator,
session::prepare_session,
};

use super::{Drive, Driver};
Expand Down Expand Up @@ -82,16 +82,15 @@ impl ClientTx {

#[cold]
#[inline(never)]
pub(super) async fn _connect(host: Host, cfg: &Config) -> Result<(Client, Driver), Error> {
pub(super) async fn _connect(host: Host, cfg: &Config) -> Result<(ClientTx, Driver), Error> {
match host {
Host::Udp(ref host) => {
let tx = connect_quic(host, cfg.get_ports()).await?;
let streams = tx.inner.open_bi().await.unwrap();
let mut drv = QuicDriver::new(streams);
let mut cli = Client::new(tx);
cli.prepare_session(&mut drv, cfg).await?;
prepare_session(&mut drv, cfg).await?;
drv.close_tx().await;
Ok((cli, Driver::quic(drv, cfg.clone())))
Ok((tx, Driver::quic(drv, cfg.clone())))
}
_ => unreachable!(),
}
Expand Down
24 changes: 10 additions & 14 deletions postgres/src/driver/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use xitca_io::{
};

use crate::{
client::Client,
config::{Config, Host, SslMode},
error::{unexpected_eof_err, write_zero_err, Error},
session::prepare_session,
};

use super::{
Expand Down Expand Up @@ -56,7 +56,7 @@ impl ClientTx {

#[cold]
#[inline(never)]
pub(super) async fn _connect(host: Host, cfg: &mut Config) -> Result<(Client, Driver), Error> {
pub(super) async fn _connect(host: Host, cfg: &mut Config) -> Result<(ClientTx, Driver), Error> {
// this block have repeated code due to HRTB limitation.
// namely for <'_> AsyncIo::Future<'_>: Send bound can not be expressed correctly.
match host {
Expand All @@ -67,19 +67,17 @@ pub(super) async fn _connect(host: Host, cfg: &mut Config) -> Result<(Client, Dr
{
let io = tls::connect(io, host, cfg).await?;
let (mut drv, tx) = GenericDriver::new(io);
let mut cli = Client::new(ClientTx(tx));
cli.prepare_session(&mut drv, cfg).await?;
Ok((cli, Driver::tls(drv, cfg.clone())))
prepare_session(&mut drv, cfg).await?;
Ok((ClientTx(tx), Driver::tls(drv, cfg.clone())))
}
#[cfg(not(feature = "tls"))]
{
Err(crate::error::FeatureError::Tls.into())
}
} else {
let (mut drv, tx) = GenericDriver::new(io);
let mut cli = Client::new(ClientTx(tx));
cli.prepare_session(&mut drv, cfg).await?;
Ok((cli, Driver::tcp(drv, cfg.clone())))
prepare_session(&mut drv, cfg).await?;
Ok((ClientTx(tx), Driver::tcp(drv, cfg.clone())))
}
}
#[cfg(unix)]
Expand All @@ -91,19 +89,17 @@ pub(super) async fn _connect(host: Host, cfg: &mut Config) -> Result<(Client, Dr
let host = host.to_string_lossy();
let io = tls::connect(io, host.as_ref(), cfg).await?;
let (mut drv, tx) = GenericDriver::new(io);
let mut cli = Client::new(ClientTx(tx));
cli.prepare_session(&mut drv, cfg).await?;
Ok((cli, Driver::unix_tls(drv, cfg.clone())))
prepare_session(&mut drv, cfg).await?;
Ok((ClientTx(tx), Driver::unix_tls(drv, cfg.clone())))
}
#[cfg(not(feature = "tls"))]
{
Err(crate::error::FeatureError::Tls.into())
}
} else {
let (mut drv, tx) = GenericDriver::new(io);
let mut cli = Client::new(ClientTx(tx));
cli.prepare_session(&mut drv, cfg).await?;
Ok((cli, Driver::unix(drv, cfg.clone())))
prepare_session(&mut drv, cfg).await?;
Ok((ClientTx(tx), Driver::unix(drv, cfg.clone())))
}
}
_ => unreachable!(),
Expand Down
Loading

0 comments on commit 9c3257b

Please sign in to comment.