From aa3b58083a30188b2179d679113ce7f7ffb8d39e Mon Sep 17 00:00:00 2001 From: baiqiaosen Date: Tue, 6 Aug 2024 15:40:31 +0800 Subject: [PATCH] TCP support SO_REUSEADDR --- src/socket/tcp.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index 267f10729..c97cd0106 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -429,6 +429,8 @@ pub struct Socket<'a> { /// Address passed to listen(). Listen address is set when listen() is called and /// used every time the socket is reset back to the LISTEN state. listen_endpoint: IpListenEndpoint, + /// Address passed to bind(). Record the binding address of the socket. + bound_endpoint: IpListenEndpoint, /// Current 4-tuple (local and remote endpoints). tuple: Option, /// The sequence number corresponding to the beginning of the transmit buffer. @@ -521,6 +523,7 @@ impl<'a> Socket<'a> { keep_alive: None, hop_limit: None, listen_endpoint: IpListenEndpoint::default(), + bound_endpoint: IpListenEndpoint::default(), tuple: None, local_seq_no: TcpSeqNumber::default(), remote_seq_no: TcpSeqNumber::default(), @@ -770,6 +773,18 @@ impl<'a> Socket<'a> { Some(self.tuple?.remote) } + /// get bound endpoint. + #[inline] + pub fn get_bound_endpoint(&self) -> IpListenEndpoint { + self.bound_endpoint + } + + /// set bound endpoint. + #[inline] + pub fn set_bound_endpoint(&mut self, bound_endpoint: IpListenEndpoint) { + self.bound_endpoint = bound_endpoint + } + /// Return the connection state, in terms of the TCP state machine. #[inline] pub fn state(&self) -> State {