aquatic_http: network: update inline hints, format code

This commit is contained in:
Joakim Frostegård 2020-07-04 13:47:22 +02:00
parent c28e764929
commit d48573a28e
2 changed files with 17 additions and 4 deletions

View file

@ -33,6 +33,7 @@ pub struct EstablishedConnection {
impl EstablishedConnection { impl EstablishedConnection {
#[inline]
fn new(stream: Stream) -> Self { fn new(stream: Stream) -> Self {
let peer_addr = stream.get_peer_addr(); let peer_addr = stream.get_peer_addr();
@ -113,6 +114,7 @@ impl EstablishedConnection {
Ok(()) Ok(())
} }
#[inline]
pub fn clear_buffer(&mut self){ pub fn clear_buffer(&mut self){
self.bytes_read = 0; self.bytes_read = 0;
self.buf = Vec::new(); self.buf = Vec::new();
@ -152,7 +154,6 @@ impl <'a>TlsHandshakeMachine {
/// Attempt to establish a TLS connection. On a WouldBlock error, return /// Attempt to establish a TLS connection. On a WouldBlock error, return
/// the machine wrapped in an error for later attempts. /// the machine wrapped in an error for later attempts.
#[inline]
pub fn establish_tls(self) -> Result<EstablishedConnection, TlsHandshakeMachineError> { pub fn establish_tls(self) -> Result<EstablishedConnection, TlsHandshakeMachineError> {
let handshake_result = match self.inner { let handshake_result = match self.inner {
TlsHandshakeMachineInner::TcpStream(stream) => { TlsHandshakeMachineInner::TcpStream(stream) => {
@ -212,9 +213,13 @@ impl Connection {
) -> Self { ) -> Self {
// Setup handshake machine if TLS is requested // Setup handshake machine if TLS is requested
let inner = if let Some(tls_acceptor) = opt_tls_acceptor { let inner = if let Some(tls_acceptor) = opt_tls_acceptor {
ConnectionInner::InProgress(TlsHandshakeMachine::new(tls_acceptor.clone(), tcp_stream)) ConnectionInner::InProgress(
TlsHandshakeMachine::new(tls_acceptor.clone(), tcp_stream)
)
} else { } else {
ConnectionInner::Established(EstablishedConnection::new(Stream::TcpStream(tcp_stream))) ConnectionInner::Established(
EstablishedConnection::new(Stream::TcpStream(tcp_stream))
)
}; };
Self { Self {
@ -223,6 +228,7 @@ impl Connection {
} }
} }
#[inline]
pub fn from_established( pub fn from_established(
valid_until: ValidUntil, valid_until: ValidUntil,
established: EstablishedConnection, established: EstablishedConnection,
@ -233,6 +239,7 @@ impl Connection {
} }
} }
#[inline]
pub fn from_in_progress( pub fn from_in_progress(
valid_until: ValidUntil, valid_until: ValidUntil,
machine: TlsHandshakeMachine, machine: TlsHandshakeMachine,
@ -243,6 +250,7 @@ impl Connection {
} }
} }
#[inline]
pub fn get_established(&mut self) -> Option<&mut EstablishedConnection> { pub fn get_established(&mut self) -> Option<&mut EstablishedConnection> {
if let ConnectionInner::Established(ref mut established) = self.inner { if let ConnectionInner::Established(ref mut established) = self.inner {
Some(established) Some(established)
@ -251,6 +259,7 @@ impl Connection {
} }
} }
#[inline]
pub fn get_in_progress(self) -> Option<TlsHandshakeMachine> { pub fn get_in_progress(self) -> Option<TlsHandshakeMachine> {
if let ConnectionInner::InProgress(machine) = self.inner { if let ConnectionInner::InProgress(machine) = self.inner {
Some(machine) Some(machine)

View file

@ -150,7 +150,11 @@ fn accept_new_streams(
.register(&mut stream, token, Interest::READABLE) .register(&mut stream, token, Interest::READABLE)
.unwrap(); .unwrap();
let connection = Connection::new(opt_tls_acceptor, valid_until, stream); let connection = Connection::new(
opt_tls_acceptor,
valid_until,
stream
);
connections.insert(token, connection); connections.insert(token, connection);
}, },