mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-18 09:35:50 +00:00
socket: Add method to get local address
This commit is contained in:
parent
7510fe3de0
commit
3b1edd8e3d
1 changed files with 5 additions and 0 deletions
|
|
@ -24,7 +24,10 @@ pub trait Socket {
|
|||
fn send(&mut self, data: &[u8]) -> GDResult<()>;
|
||||
fn receive(&mut self, size: Option<usize>) -> GDResult<Vec<u8>>;
|
||||
|
||||
/// Get the remote port
|
||||
fn port(&self) -> u16;
|
||||
/// Get the local SocketAddr
|
||||
fn local_addr(&self) -> std::io::Result<SocketAddr>;
|
||||
}
|
||||
|
||||
pub struct TcpSocket {
|
||||
|
|
@ -73,6 +76,7 @@ impl Socket for TcpSocket {
|
|||
}
|
||||
|
||||
fn port(&self) -> u16 { self.address.port() }
|
||||
fn local_addr(&self) -> std::io::Result<SocketAddr> { self.socket.local_addr() }
|
||||
}
|
||||
|
||||
pub struct UdpSocket {
|
||||
|
|
@ -121,6 +125,7 @@ impl Socket for UdpSocket {
|
|||
}
|
||||
|
||||
fn port(&self) -> u16 { self.address.port() }
|
||||
fn local_addr(&self) -> std::io::Result<SocketAddr> { self.socket.local_addr() }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue