Avoid short writes if a buffer is full.

write_buf() tries to write as much as it can in one go, and can return
without writing the whole buffer. We need to use write_all() instead.
This commit is contained in:
Heikki Linnakangas
2021-04-14 18:18:38 +03:00
parent d1d6c968d5
commit 6266fd102c

View File

@@ -317,7 +317,7 @@ impl Connection {
.await?;
self.stream.write_i16(1).await?;
self.stream.write_buf(&mut b).await?;
self.stream.write_all(&mut b).await?;
self.stream.write_i32(0).await?; /* table oid */
self.stream.write_i16(0).await?; /* attnum */
self.stream.write_i32(25).await?; /* TEXTOID */
@@ -336,7 +336,7 @@ impl Connection {
self.stream.write_i16(1).await?;
self.stream.write_i32(b.len() as i32).await?;
self.stream.write_buf(&mut b).await?;
self.stream.write_all(&mut b).await?;
}
BeMessage::ControlFile => {
@@ -348,7 +348,7 @@ impl Connection {
self.stream.write_i16(1).await?;
self.stream.write_i32(b.len() as i32).await?;
self.stream.write_buf(&mut b).await?;
self.stream.write_all(&mut b).await?;
}
BeMessage::CommandComplete => {
@@ -356,7 +356,7 @@ impl Connection {
self.stream.write_u8(b'C').await?;
self.stream.write_i32(4 + b.len() as i32).await?;
self.stream.write_buf(&mut b).await?;
self.stream.write_all(&mut b).await?;
}
BeMessage::ZenithStatusResponse(resp) => {
@@ -383,7 +383,7 @@ impl Connection {
self.stream.write_u8(102).await?; /* tag from pagestore_client.h */
self.stream.write_u8(resp.ok as u8).await?;
self.stream.write_u32(resp.n_blocks).await?;
self.stream.write_buf(&mut resp.page.clone()).await?;
self.stream.write_all(&mut resp.page.clone()).await?;
}
}
@@ -404,7 +404,7 @@ impl Connection {
match m.kind {
StartupRequestCode::NegotiateGss | StartupRequestCode::NegotiateSsl => {
let mut b = Bytes::from("N");
self.stream.write_buf(&mut b).await?;
self.stream.write_all(&mut b).await?;
self.stream.flush().await?;
}
StartupRequestCode::Normal => {