mirror of
https://github.com/lbl8603/vnts.git
synced 2025-12-24 12:47:51 +08:00
增长tcp读取长度
This commit is contained in:
@@ -29,7 +29,12 @@ async fn stream_handle(stream: TcpStream, addr: SocketAddr, handler: PacketHandl
|
||||
while let Some(data) = receiver.recv().await {
|
||||
let len = data.len();
|
||||
if let Err(e) = w
|
||||
.write_all(&[0, 0, (len >> 8) as u8, (len & 0xFF) as u8])
|
||||
.write_all(&[
|
||||
(len >> 24) as u8,
|
||||
(len >> 16) as u8,
|
||||
(len >> 8) as u8,
|
||||
len as u8,
|
||||
])
|
||||
.await
|
||||
{
|
||||
log::info!("发送失败,链接终止:{:?},{:?}", addr, e);
|
||||
@@ -60,7 +65,10 @@ async fn tcp_read(
|
||||
let sender = Some(sender);
|
||||
loop {
|
||||
read.read_exact(&mut head).await?;
|
||||
let len = ((head[2] as usize) << 8) | head[3] as usize;
|
||||
let len = ((head[0] as usize) << 24)
|
||||
| ((head[1] as usize) << 16)
|
||||
| ((head[2] as usize) << 8)
|
||||
| head[3] as usize;
|
||||
if len < 12 || len > buf.len() {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
|
||||
@@ -126,8 +126,7 @@ impl<B: AsRef<[u8]>> NetPacket<B> {
|
||||
"length overflow",
|
||||
));
|
||||
}
|
||||
// 不能大于udp最大载荷长度
|
||||
if !(12..=65535 - 20 - 8).contains(&data_len) {
|
||||
if HEAD_LEN > data_len {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
"length overflow",
|
||||
|
||||
Reference in New Issue
Block a user