Buffer client CopyData messages (#284)

Buffers CopyData messages and removes buffer clone for the sync message
This commit is contained in:
zainkabani
2023-01-17 20:39:55 -05:00
committed by GitHub
parent 7894bba59b
commit 85ac3ef9a5
4 changed files with 44 additions and 34 deletions

View File

@@ -258,7 +258,7 @@ where
res.put_i32(len);
res.put_slice(&set_complete[..]);
write_all_half(stream, res).await?;
write_all_half(stream, &res).await?;
ready_for_query(stream).await
}
@@ -308,7 +308,7 @@ where
res.put_i32(error.len() as i32 + 4);
res.put(error);
write_all_half(stream, res).await
write_all_half(stream, &res).await
}
pub async fn wrong_password<S>(stream: &mut S, user: &str) -> Result<(), Error>
@@ -370,7 +370,7 @@ where
// CommandComplete
res.put(command_complete("SELECT 1"));
write_all_half(stream, res).await?;
write_all_half(stream, &res).await?;
ready_for_query(stream).await
}
@@ -459,11 +459,11 @@ where
}
/// Write all the data in the buffer to the TcpStream, write owned half (see mpsc).
pub async fn write_all_half<S>(stream: &mut S, buf: BytesMut) -> Result<(), Error>
pub async fn write_all_half<S>(stream: &mut S, buf: &BytesMut) -> Result<(), Error>
where
S: tokio::io::AsyncWrite + std::marker::Unpin,
{
match stream.write_all(&buf).await {
match stream.write_all(buf).await {
Ok(_) => Ok(()),
Err(_) => return Err(Error::SocketError(format!("Error writing to socket"))),
}