Clean up PSH flag handling.

This commit is contained in:
whitequark 2017-09-22 06:29:25 +00:00
parent d7da46fd3b
commit b6e4e23868
2 changed files with 10 additions and 12 deletions

View File

@ -939,16 +939,8 @@ impl<'a> TcpSocket<'a> {
} }
} }
// We don't care about the PSH flag.
let control =
if repr.control == TcpControl::Psh {
TcpControl::None
} else {
repr.control
};
// Validate and update the state. // Validate and update the state.
match (self.state, control) { match (self.state, repr.control.quash_psh()) {
// RSTs are not accepted in the LISTEN state. // RSTs are not accepted in the LISTEN state.
(State::Listen, TcpControl::Rst) => (State::Listen, TcpControl::Rst) =>
return Err(Error::Dropped), return Err(Error::Dropped),
@ -1493,9 +1485,7 @@ mod test {
(recv(&mut $socket, $time, |result| { (recv(&mut $socket, $time, |result| {
// Most of the time we don't care about the PSH flag. // Most of the time we don't care about the PSH flag.
let result = result.map(|mut repr| { let result = result.map(|mut repr| {
if repr.control == TcpControl::Psh { repr.control = repr.control.quash_psh();
repr.control = TcpControl::None;
}
repr repr
}); });
assert_eq!(result, $result) assert_eq!(result, $result)

View File

@ -617,6 +617,14 @@ impl Control {
_ => 0 _ => 0
} }
} }
/// Turn the PSH flag into no flag, and keep the rest as-is.
pub fn quash_psh(self) -> Control {
match self {
Control::Psh => Control::None,
_ => self
}
}
} }
/// A high-level representation of a Transmission Control Protocol packet. /// A high-level representation of a Transmission Control Protocol packet.