Fix TCP command interface rx buffer wrapping
Previously, if a message spanned the end of the receive ring buffer, the last byte in the buffer would be missing from the to-be-decoded message, leading to a parse error or panic. With this commit, >3M commands were exchanged over one socket without further issues.
This commit is contained in:
parent
bc85cd478b
commit
2297286360
|
@ -852,7 +852,7 @@ impl Server {
|
||||||
self.discard = true;
|
self.discard = true;
|
||||||
self.data.clear();
|
self.data.clear();
|
||||||
} else if !self.discard && len > 0 {
|
} else if !self.discard && len > 0 {
|
||||||
self.data.extend_from_slice(&buf[..len - 1]).unwrap();
|
self.data.extend_from_slice(&buf[..len]).unwrap();
|
||||||
}
|
}
|
||||||
(len, found)
|
(len, found)
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
@ -862,7 +862,7 @@ impl Server {
|
||||||
json_reply(socket, &Response { code: 520, message: "command buffer overflow" });
|
json_reply(socket, &Response { code: 520, message: "command buffer overflow" });
|
||||||
self.data.clear();
|
self.data.clear();
|
||||||
} else {
|
} else {
|
||||||
let r = from_slice::<T>(&self.data);
|
let r = from_slice::<T>(&self.data[..self.data.len() - 1]);
|
||||||
self.data.clear();
|
self.data.clear();
|
||||||
match r {
|
match r {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
|
|
Loading…
Reference in New Issue