Fix erratic packet delivery times with `BufWriter`

The data was being delievered in different batches, which
caused problems. This commit replaces the current stream
writer with a buffered writer ensuring good delivery.

Signed-off-by: Sayan Nandan <nandansayan@outlook.com>
next
Sayan Nandan 4 years ago
parent e92a6eb8c1
commit d3387b68d0
No known key found for this signature in database
GPG Key ID: C31EFD7DDA12AEE0

@ -36,6 +36,7 @@ use openssl::ssl::{Ssl, SslAcceptor, SslFiletype, SslMethod};
use std::net::SocketAddr;
use std::pin::Pin;
use std::sync::Arc;
use tokio::io::BufWriter;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream};
use tokio::sync::Semaphore;
@ -183,14 +184,14 @@ impl Drop for SslConnectionHandler {
}
pub struct SslConnection {
stream: SslStream<TcpStream>,
stream: BufWriter<SslStream<TcpStream>>,
buffer: BytesMut,
}
impl SslConnection {
pub fn new(stream: SslStream<TcpStream>) -> Self {
SslConnection {
stream: stream,
stream: BufWriter::new(stream),
buffer: BytesMut::with_capacity(BUF_CAP),
}
}
@ -218,7 +219,7 @@ impl SslConnection {
}
}
fn get_peer(&self) -> IoResult<SocketAddr> {
self.stream.get_ref().peer_addr()
self.stream.get_ref().get_ref().peer_addr()
}
/// Try to parse a query from the buffered data
fn try_query(&mut self) -> Result<ParseResult, ()> {

@ -72,6 +72,15 @@ impl IsConnection for SslStream<TcpStream> {
}
}
impl IsConnection for BufWriter<SslStream<TcpStream>> {
fn write_lowlevel<'s>(
&'s mut self,
bytes: &'s [u8],
) -> Pin<Box<dyn Future<Output = Result<usize, IoError>> + Send + Sync + 's>> {
Box::pin(self.write(bytes))
}
}
/// A `BytesWrapper` object wraps around a `Bytes` object that might have been pulled
/// from `CoreDB`.
///

Loading…
Cancel
Save