Skip to content

Commit

Permalink
Add local_addr and ttl functions to TcpAcceptor (#640)
Browse files Browse the repository at this point in the history
* Add local_addr and ttl functions to `TcpAcceptor`

* Format Rust code using rustfmt

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
chrislearn and github-actions[bot] authored Jan 15, 2024
1 parent 6ebfaf3 commit 3cc1bf4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions crates/core/src/conn/tcp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! TcpListener and it's implements.
use std::io::{Error as IoError, ErrorKind, Result as IoResult};
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
use std::vec;
Expand Down Expand Up @@ -112,6 +113,29 @@ pub struct TcpAcceptor {
holdings: Vec<Holding>,
}

impl TcpAcceptor {
/// Returns the local address that this listener is bound to.
///
/// This can be useful, for example, when binding to port 0 to figure out
/// which port was actually bound.
pub fn local_addr(&self) -> IoResult<SocketAddr> {
self.inner.local_addr()
}

/// Gets the value of the `IP_TTL` option for this socket.
pub fn ttl(&self) -> IoResult<u32> {
self.inner.ttl()
}

/// Sets the value for the `IP_TTL` option on this socket.
///
/// This value sets the time-to-live field that is used in every packet sent
/// from this socket.
pub fn set_ttl(&self, ttl: u32) -> IoResult<()> {
self.inner.set_ttl(ttl)
}
}

impl TryFrom<TokioTcpListener> for TcpAcceptor {
type Error = IoError;
fn try_from(inner: TokioTcpListener) -> Result<Self, Self::Error> {
Expand Down

0 comments on commit 3cc1bf4

Please sign in to comment.