Skip to content

Commit

Permalink
Move setting nonblocking on MicroHTTP to its own method
Browse files Browse the repository at this point in the history
This allows a choice instead of forcing nonblocking which
results in high CPU usage if you wait for connections in a loop.
  • Loading branch information
dexgs committed Jun 22, 2021
1 parent 84adbef commit fd97725
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/microhttp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ impl MicroHTTP {
// Create listener using the requested interface
let listener = TcpListener::bind(interface)?;

// Set to non-blocking so we can later check if we have clients
// without blocking the whole thread.
listener.set_nonblocking(true)?;

// Return created instance
Ok(MicroHTTP {
listener : listener
})
}

/// Set whether or not the underlying TcpListener awaits connections in nonblocking mode
pub fn set_nonblocking(&mut self, state: bool) -> Result<(), io::Error> {
self.listener.set_nonblocking(state)
}


/// Return the next available client which is incoming at this server.
///
/// Returns either:
Expand Down

0 comments on commit fd97725

Please sign in to comment.