Skip to content

Commit

Permalink
Clean up PSH flag handling.
Browse files Browse the repository at this point in the history
whitequark committed Sep 22, 2017
1 parent c43446f commit af51f2a
Showing 2 changed files with 10 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
@@ -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.
match (self.state, control) {
match (self.state, repr.control.quash_psh()) {
// RSTs are not accepted in the LISTEN state.
(State::Listen, TcpControl::Rst) =>
return Err(Error::Dropped),
@@ -1493,9 +1485,7 @@ mod test {
(recv(&mut $socket, $time, |result| {
// Most of the time we don't care about the PSH flag.
let result = result.map(|mut repr| {
if repr.control == TcpControl::Psh {
repr.control = TcpControl::None;
}
repr.control = repr.control.quash_psh();
repr
});
assert_eq!(result, $result)
8 changes: 8 additions & 0 deletions src/wire/tcp.rs
Original file line number Diff line number Diff line change
@@ -617,6 +617,14 @@ impl Control {
_ => 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.

0 comments on commit af51f2a

Please sign in to comment.