Skip to content

Commit

Permalink
fix default build on windows. (#1016)
Browse files Browse the repository at this point in the history
* fix default build on windows.

* fix build.
  • Loading branch information
fakeshadow authored Apr 4, 2024
1 parent c4c5b33 commit 30301ae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
41 changes: 24 additions & 17 deletions postgres/src/driver/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,33 @@ pub(super) async fn connect(host: Host, cfg: &mut Config) -> Result<(DriverTx, D
Ok((tx, Driver::tcp(drv)))
}
}
#[cfg(unix)]
Host::Unix(ref host) => {
let mut io = xitca_io::net::UnixStream::connect(host).await?;
if should_connect_tls(&mut io, cfg).await? {
#[cfg(feature = "tls")]
{
let host = host.to_string_lossy();
let io = super::tls::connect_tls(io, host.as_ref(), cfg).await?;
Host::Unix(ref _host) => {
#[cfg(unix)]
{
let mut io = xitca_io::net::UnixStream::connect(_host).await?;
if should_connect_tls(&mut io, cfg).await? {
#[cfg(feature = "tls")]
{
let host = _host.to_string_lossy();
let io = super::tls::connect_tls(io, host.as_ref(), cfg).await?;
let (mut drv, tx) = GenericDriver::new(io);
prepare_session(&mut drv, cfg).await?;
Ok((tx, Driver::unix_tls(drv)))
}
#[cfg(not(feature = "tls"))]
{
Err(crate::error::FeatureError::Tls.into())
}
} else {
let (mut drv, tx) = GenericDriver::new(io);
prepare_session(&mut drv, cfg).await?;
Ok((tx, Driver::unix_tls(drv)))
}
#[cfg(not(feature = "tls"))]
{
Err(crate::error::FeatureError::Tls.into())
Ok((tx, Driver::unix(drv)))
}
} else {
let (mut drv, tx) = GenericDriver::new(io);
prepare_session(&mut drv, cfg).await?;
Ok((tx, Driver::unix(drv)))
}

#[cfg(not(unix))]
{
panic!("Host::Unix only support unix platform")
}
}
Host::Quic(ref _host) => {
Expand Down
17 changes: 5 additions & 12 deletions postgres/src/driver/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,23 @@ where
}

let interest = if self.write_buf.want_write_io() {
Interest::READABLE | Interest::WRITABLE
Interest::READABLE.add(Interest::WRITABLE)
} else {
Interest::READABLE
};

let select = match self.state {
DriverState::Running(ref mut rx) => {
let ready = self.io.ready(interest);
rx.recv().select(ready).await
}
DriverState::Running(ref mut rx) => rx.recv().select(self.io.ready(interest)).await,
DriverState::Closing(ref mut e) => {
if !interest.is_writable() && self.res.is_empty() {
// no interest to write to io and all response have been finished so
// shutdown io and exit.
// if there is a better way to exhaust potential remaining backend message
// please file an issue.
poll_fn(|cx| Pin::new(&mut self.io).poll_shutdown(cx)).await?;

return e.take().map(|e| Err(e.into())).transpose();
}
let ready = self.io.ready(interest);
SelectOutput::B(ready.await)
SelectOutput::B(self.io.ready(interest).await)
}
};

Expand Down Expand Up @@ -164,8 +159,7 @@ where
if let Some(o) = func(self.read_buf.get_mut()) {
return o;
}
let ready = self.io.ready(Interest::READABLE);
ready.await?;
self.io.ready(Interest::READABLE).await?;
self.try_read()?;
}
}
Expand Down Expand Up @@ -227,8 +221,7 @@ where
if self.write_buf.is_empty() {
return Ok(());
}
let ready = self.io.ready(Interest::WRITABLE);
ready.await?;
self.io.ready(Interest::WRITABLE).await?;
}
}

Expand Down
4 changes: 2 additions & 2 deletions postgres/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
sync::Arc,
};

use quinn::{Connecting, Endpoint, ServerConfig};
use quinn::{Endpoint, Incoming, ServerConfig};
use rustls_0dot21::{Certificate, PrivateKey};
use tracing::error;
use xitca_io::{
Expand Down Expand Up @@ -116,7 +116,7 @@ fn cfg_from_cert(cert: impl AsRef<Path>, key: impl AsRef<Path>) -> Result<Server
Ok(ServerConfig::with_crypto(Arc::new(config)))
}

async fn listen_task(conn: Connecting, addr: SocketAddr) -> Result<(), Error> {
async fn listen_task(conn: Incoming, addr: SocketAddr) -> Result<(), Error> {
let conn = conn.await?;

let mut upstream = TcpStream::connect(addr).await?;
Expand Down

0 comments on commit 30301ae

Please sign in to comment.