Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Server::local_addr #7

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Reactor {
&self,
source: &Source,
direction: usize,
cx: &mut Context<'_>,
cx: &Context<'_>,
) -> Poll<io::Result<()>> {
if source.triggered[direction].load(Ordering::Acquire) {
return Poll::Ready(Ok(()));
Expand Down Expand Up @@ -189,7 +189,7 @@ impl TcpStream {
&self,
direction: usize,
mut f: impl FnMut() -> io::Result<T>,
cx: &mut Context<'_>,
cx: &Context<'_>,
) -> Poll<io::Result<T>> {
loop {
if self
Expand Down
9 changes: 9 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ impl Server {
self
}

/// Get the local address of the bound socket
pub fn local_addr(&self) -> Option<io::Result<SocketAddr>> {
let listener = self.listener.as_ref()?;
let addr = listener
.local_addr()
.map_err(|_e| io::Error::new(io::ErrorKind::Other, "Server::bind not called yet"));
Some(addr)
}

fn configure<T>(&self, http: &mut Http<T>) {
macro_rules! configure {
($self:ident, $other:expr, [$($option:ident),* $(,)?], [$($other_option:ident => $this_option:ident),* $(,)?]) => {{
Expand Down
Loading