@@ -401,6 +401,53 @@ impl TcpStream {
401401 self . 0 . peek ( buf)
402402 }
403403
404+ /// Sets the value of the `SO_LINGER` option on this socket.
405+ ///
406+ /// This value controls how the socket is closed when data remains
407+ /// to be sent. If `SO_LINGER` is set, the socket will remain open
408+ /// for the specified duration as the system attempts to send pending data.
409+ /// Otherwise, the system may close the socket immediately, or wait for a
410+ /// default timeout.
411+ ///
412+ /// # Examples
413+ ///
414+ /// ```no_run
415+ /// #![feature(tcp_linger)]
416+ ///
417+ /// use std::net::TcpStream;
418+ /// use std::time::Duration;
419+ ///
420+ /// let stream = TcpStream::connect("127.0.0.1:8080")
421+ /// .expect("Couldn't connect to the server...");
422+ /// stream.set_linger(Some(Duration::from_secs(0))).expect("set_linger call failed");
423+ /// ```
424+ #[ unstable( feature = "tcp_linger" , issue = "88494" ) ]
425+ pub fn set_linger ( & self , linger : Option < Duration > ) -> io:: Result < ( ) > {
426+ self . 0 . set_linger ( linger)
427+ }
428+
429+ /// Gets the value of the `SO_LINGER` option on this socket.
430+ ///
431+ /// For more information about this option, see [`TcpStream::set_linger`].
432+ ///
433+ /// # Examples
434+ ///
435+ /// ```no_run
436+ /// #![feature(tcp_linger)]
437+ ///
438+ /// use std::net::TcpStream;
439+ /// use std::time::Duration;
440+ ///
441+ /// let stream = TcpStream::connect("127.0.0.1:8080")
442+ /// .expect("Couldn't connect to the server...");
443+ /// stream.set_linger(Some(Duration::from_secs(0))).expect("set_linger call failed");
444+ /// assert_eq!(stream.linger().unwrap(), Some(Duration::from_secs(0)));
445+ /// ```
446+ #[ unstable( feature = "tcp_linger" , issue = "88494" ) ]
447+ pub fn linger ( & self ) -> io:: Result < Option < Duration > > {
448+ self . 0 . linger ( )
449+ }
450+
404451 /// Sets the value of the `TCP_NODELAY` option on this socket.
405452 ///
406453 /// If set, this option disables the Nagle algorithm. This means that
0 commit comments