Merge pull request #777 from petrosagg/buffered-io
tokio-postgres: buffer sockets to avoid excessive syscalls
This commit is contained in:
commit
3390cf33ed
@ -51,7 +51,7 @@ use std::future::Future;
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
|
use tokio::io::{AsyncRead, AsyncWrite, BufReader, ReadBuf};
|
||||||
use tokio_postgres::tls;
|
use tokio_postgres::tls;
|
||||||
#[cfg(feature = "runtime")]
|
#[cfg(feature = "runtime")]
|
||||||
use tokio_postgres::tls::MakeTlsConnect;
|
use tokio_postgres::tls::MakeTlsConnect;
|
||||||
@ -115,6 +115,7 @@ where
|
|||||||
type Future = Pin<Box<dyn Future<Output = Result<TlsStream<S>, native_tls::Error>> + Send>>;
|
type Future = Pin<Box<dyn Future<Output = Result<TlsStream<S>, native_tls::Error>> + Send>>;
|
||||||
|
|
||||||
fn connect(self, stream: S) -> Self::Future {
|
fn connect(self, stream: S) -> Self::Future {
|
||||||
|
let stream = BufReader::with_capacity(8192, stream);
|
||||||
let future = async move {
|
let future = async move {
|
||||||
let stream = self.connector.connect(&self.domain, stream).await?;
|
let stream = self.connector.connect(&self.domain, stream).await?;
|
||||||
|
|
||||||
@ -126,7 +127,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The stream returned by `TlsConnector`.
|
/// The stream returned by `TlsConnector`.
|
||||||
pub struct TlsStream<S>(tokio_native_tls::TlsStream<S>);
|
pub struct TlsStream<S>(tokio_native_tls::TlsStream<BufReader<S>>);
|
||||||
|
|
||||||
impl<S> AsyncRead for TlsStream<S>
|
impl<S> AsyncRead for TlsStream<S>
|
||||||
where
|
where
|
||||||
|
@ -57,7 +57,7 @@ use std::pin::Pin;
|
|||||||
#[cfg(feature = "runtime")]
|
#[cfg(feature = "runtime")]
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
|
use tokio::io::{AsyncRead, AsyncWrite, BufReader, ReadBuf};
|
||||||
use tokio_openssl::SslStream;
|
use tokio_openssl::SslStream;
|
||||||
use tokio_postgres::tls;
|
use tokio_postgres::tls;
|
||||||
#[cfg(feature = "runtime")]
|
#[cfg(feature = "runtime")]
|
||||||
@ -140,6 +140,7 @@ where
|
|||||||
type Future = Pin<Box<dyn Future<Output = Result<TlsStream<S>, Self::Error>> + Send>>;
|
type Future = Pin<Box<dyn Future<Output = Result<TlsStream<S>, Self::Error>> + Send>>;
|
||||||
|
|
||||||
fn connect(self, stream: S) -> Self::Future {
|
fn connect(self, stream: S) -> Self::Future {
|
||||||
|
let stream = BufReader::with_capacity(8192, stream);
|
||||||
let future = async move {
|
let future = async move {
|
||||||
let ssl = self.ssl.into_ssl(&self.domain)?;
|
let ssl = self.ssl.into_ssl(&self.domain)?;
|
||||||
let mut stream = SslStream::new(ssl, stream)?;
|
let mut stream = SslStream::new(ssl, stream)?;
|
||||||
@ -182,7 +183,7 @@ impl Error for ConnectError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The stream returned by `TlsConnector`.
|
/// The stream returned by `TlsConnector`.
|
||||||
pub struct TlsStream<S>(SslStream<S>);
|
pub struct TlsStream<S>(SslStream<BufReader<S>>);
|
||||||
|
|
||||||
impl<S> AsyncRead for TlsStream<S>
|
impl<S> AsyncRead for TlsStream<S>
|
||||||
where
|
where
|
||||||
|
Loading…
Reference in New Issue
Block a user