mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'xMAC94x/tcp_read_buf' into 'master'
switch from `read` to `read_buf` in tcp sink. also always reserve 4 times 1500... See merge request veloren/veloren!3445
This commit is contained in:
commit
80cad63633
@ -494,13 +494,15 @@ impl UnreliableSink for TcpSink {
|
|||||||
type DataFormat = BytesMut;
|
type DataFormat = BytesMut;
|
||||||
|
|
||||||
async fn recv(&mut self) -> Result<Self::DataFormat, ProtocolError<Self::CustomErr>> {
|
async fn recv(&mut self) -> Result<Self::DataFormat, ProtocolError<Self::CustomErr>> {
|
||||||
self.buffer.resize(1500, 0u8);
|
if self.buffer.capacity() < 1500 {
|
||||||
match self.half.read(&mut self.buffer).await {
|
self.buffer.reserve(1500 * 4); // reserve multiple, so that we alloc less often
|
||||||
|
}
|
||||||
|
match self.half.read_buf(&mut self.buffer).await {
|
||||||
Ok(0) => Err(ProtocolError::Custom(ProtocolsError::Tcp(io::Error::new(
|
Ok(0) => Err(ProtocolError::Custom(ProtocolsError::Tcp(io::Error::new(
|
||||||
io::ErrorKind::BrokenPipe,
|
io::ErrorKind::BrokenPipe,
|
||||||
"read returned 0 bytes",
|
"read returned 0 bytes",
|
||||||
)))),
|
)))),
|
||||||
Ok(n) => Ok(self.buffer.split_to(n)),
|
Ok(_) => Ok(self.buffer.split()),
|
||||||
Err(e) => Err(ProtocolError::Custom(ProtocolsError::Tcp(e))),
|
Err(e) => Err(ProtocolError::Custom(ProtocolsError::Tcp(e))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user