tcpd: Fix behavior when reading to small buffer
This commit is contained in:
parent
ae4bcb43e7
commit
e695897fe8
|
@ -574,12 +574,16 @@ impl SchemeMut for Tcpd {
|
|||
Handle::Tcp(ref mut handle) => {
|
||||
if ! handle.is_connected() {
|
||||
return Err(Error::new(ENOTCONN));
|
||||
} else if let Some((_ip, tcp)) = handle.data.pop_front() {
|
||||
} else if let Some((ip, mut tcp)) = handle.data.pop_front() {
|
||||
let mut i = 0;
|
||||
while i < buf.len() && i < tcp.data.len() {
|
||||
buf[i] = tcp.data[i];
|
||||
let mut len = std::cmp::min(buf.len(), tcp.data.len());
|
||||
for c in tcp.data.drain(0..len) {
|
||||
buf[i] = c;
|
||||
i += 1;
|
||||
}
|
||||
if !tcp.data.is_empty() {
|
||||
handle.data.push_front((ip, tcp));
|
||||
}
|
||||
|
||||
return Ok(i);
|
||||
} else if handle.flags & O_NONBLOCK == O_NONBLOCK || handle.read_closed() {
|
||||
|
|
Loading…
Reference in a new issue