mirror of
https://github.com/netbirdio/IronRDP.git
synced 2026-05-22 18:43:12 -07:00
refactor(blocking): let read_by_hint() optionally accumulate unmatched bytes
The caller can then decide what to do. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
committed by
Benoît Cortier
parent
98e7dbab99
commit
6f779406e6
@@ -167,7 +167,7 @@ where
|
||||
);
|
||||
|
||||
let pdu = framed
|
||||
.read_by_hint(next_pdu_hint)
|
||||
.read_by_hint(next_pdu_hint, None)
|
||||
.map_err(|e| ironrdp_connector::custom_err!("read frame by hint", e))?;
|
||||
|
||||
trace!(length = pdu.len(), "PDU received");
|
||||
@@ -202,7 +202,7 @@ where
|
||||
);
|
||||
|
||||
let pdu = framed
|
||||
.read_by_hint(next_pdu_hint)
|
||||
.read_by_hint(next_pdu_hint, None)
|
||||
.map_err(|e| ironrdp_connector::custom_err!("read frame by hint", e))?;
|
||||
|
||||
trace!(length = pdu.len(), "PDU received");
|
||||
|
||||
@@ -87,14 +87,21 @@ where
|
||||
}
|
||||
|
||||
/// Reads a frame using the provided PduHint.
|
||||
pub fn read_by_hint(&mut self, hint: &dyn PduHint) -> io::Result<Bytes> {
|
||||
pub fn read_by_hint(&mut self, hint: &dyn PduHint, mut unmatched: Option<&mut Vec<Bytes>>) -> io::Result<Bytes> {
|
||||
loop {
|
||||
match hint
|
||||
.find_size(self.peek())
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?
|
||||
{
|
||||
Some((_matched, length)) => {
|
||||
return Ok(self.read_exact(length)?.freeze());
|
||||
Some((matched, length)) => {
|
||||
let bytes = self.read_exact(length)?.freeze();
|
||||
if matched {
|
||||
return Ok(bytes);
|
||||
} else if let Some(ref mut unmatched) = unmatched {
|
||||
unmatched.push(bytes);
|
||||
} else {
|
||||
warn!("Received and lost an unexpected PDU");
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let len = self.read()?;
|
||||
|
||||
Reference in New Issue
Block a user