Skip to content

Commit

Permalink
no need to pass the front timeout value from the poll loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Nov 26, 2020
1 parent 8db6951 commit 4fa0467
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,11 @@ impl ProxySession for Session {
result
}

fn timeout(&mut self, token: Token, timeout: &Duration) -> SessionResult {
fn timeout(&mut self, token: Token) -> SessionResult {
match *unwrap_msg!(self.protocol.as_mut()) {
State::Expect(_) => SessionResult::CloseSession,
State::Http(ref mut http) => http.timeout(token, timeout, &mut self.metrics),
State::WebSocket(ref mut pipe) => pipe.timeout(token, timeout, &mut self.metrics),
State::Http(ref mut http) => http.timeout(token, &mut self.metrics),
State::WebSocket(ref mut pipe) => pipe.timeout(token, &mut self.metrics),
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/https_openssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,14 +616,14 @@ impl ProxySession for Session {
result
}

fn timeout(&mut self, token: Token, timeout: &Duration) -> SessionResult {
fn timeout(&mut self, token: Token) -> SessionResult {
match *unwrap_msg!(self.protocol.as_mut()) {
State::Expect(_,_) => SessionResult::CloseSession,
State::Handshake(_) => SessionResult::CloseSession,
State::WebSocket(_) => SessionResult::CloseSession,
//FIXME: not implemented yet
State::Http2(_) => SessionResult::CloseSession,
State::Http(ref mut http) => http.timeout(token, timeout, &mut self.metrics),
State::Http(ref mut http) => http.timeout(token, &mut self.metrics),
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/https_rustls/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,9 @@ impl ProxySession for Session {
result
}

fn timeout(&mut self, token: Token, timeout: &Duration) -> SessionResult {
fn timeout(&mut self, token: Token) -> SessionResult {
match *unwrap_msg!(self.protocol.as_mut()) {
State::Http(ref mut http) => http.timeout(token, timeout, &mut self.metrics),
State::Http(ref mut http) => http.timeout(token, &mut self.metrics),
_ => SessionResult::CloseSession,
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub trait ProxySession {
fn process_events(&mut self, token: Token, events: Ready);
fn close(&mut self, poll: &mut Poll) -> CloseResult;
fn close_backend(&mut self, token: Token, poll: &mut Poll);
fn timeout(&mut self, t: Token, front_timeout: &Duration) -> SessionResult;
fn timeout(&mut self, t: Token) -> SessionResult;
fn last_event(&self) -> Instant;
fn print_state(&self);
fn tokens(&self) -> Vec<Token>;
Expand Down
8 changes: 5 additions & 3 deletions lib/src/protocol/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,12 +1434,14 @@ impl<Front:SocketHandler> Http<Front> {
.unwrap_or(true)
}

pub fn timeout(&mut self, token: Token, front_timeout: &Duration, metrics: &mut SessionMetrics) -> SessionResult {
pub fn timeout(&mut self, token: Token, metrics: &mut SessionMetrics) -> SessionResult {
info!("got timeout for token: {:?}", token);
if self.frontend_token == token {
let dur = Instant::now() - self.frontend_last_event;
if dur < *front_timeout {
let front_timeout = self.front_timeout.duration();
if dur < front_timeout {
TIMER.with(|timer| {
timer.borrow_mut().set_timeout(*front_timeout - dur, token);
timer.borrow_mut().set_timeout(front_timeout - dur, token);
});
SessionResult::Continue
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/protocol/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<Front:SocketHandler> Pipe<Front> {
self.backend_token
}

pub fn timeout(&mut self, _token: Token, _front_timeout: &Duration, _metrics: &mut SessionMetrics) -> SessionResult {
pub fn timeout(&mut self, _token: Token, _metrics: &mut SessionMetrics) -> SessionResult {
//FIXME
SessionResult::CloseSession
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ impl Server {

let session_token = token.0;
if self.sessions.contains(session_token) {
let order = self.sessions[session_token].borrow_mut().timeout(token, &self.front_timeout);
let order = self.sessions[session_token].borrow_mut().timeout(token);
self.interpret_session_order(SessionToken(session_token), order);
}
}
Expand Down Expand Up @@ -1487,9 +1487,9 @@ impl ProxySession for ListenSession {
fn close_backend(&mut self, _token: Token, _poll: &mut Poll) {
}

fn timeout(&mut self, _token: Token, _front_timeout: &Duration) -> SessionResult {
error!("called ProxySession::timeout(token={:?}, time, front_timeout = {:?}) on ListenSession {{ protocol: {:?} }}",
_token, _front_timeout, self.protocol);
fn timeout(&mut self, _token: Token) -> SessionResult {
error!("called ProxySession::timeout(token={:?}, time) on ListenSession {{ protocol: {:?} }}",
_token, self.protocol);
SessionResult::CloseSession
}
}
Expand Down
7 changes: 4 additions & 3 deletions lib/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,13 @@ impl ProxySession for Session {
result
}

fn timeout(&mut self, token: Token, front_timeout: &Duration) -> SessionResult {
fn timeout(&mut self, token: Token) -> SessionResult {
if self.frontend_token == token {
let dur = Instant::now() - self.last_event;
if dur < *front_timeout {
let front_timeout = self.front_timeout.duration();
if dur < front_timeout {
TIMER.with(|timer| {
timer.borrow_mut().set_timeout(*front_timeout - dur, token);
timer.borrow_mut().set_timeout(front_timeout - dur, token);
});
SessionResult::Continue
} else {
Expand Down
4 changes: 4 additions & 0 deletions lib/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ impl TimeoutContainer {
self.duration = duration;
}

pub fn duration(&mut self) -> Duration {
self.duration
}

pub fn cancel(&mut self) -> bool {
match self.timeout.take() {
None => {
Expand Down

0 comments on commit 4fa0467

Please sign in to comment.