net: add missing doc cfg on TcpSocket (#3137)

This adds the missing `net` feature flag in the generated API
documentation.
This commit is contained in:
Carl Lerche 2020-11-13 11:05:22 -08:00 committed by GitHub
parent 02b1117dca
commit 850bfc9efa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,79 +9,81 @@ use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
#[cfg(windows)] #[cfg(windows)]
use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket}; use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket};
/// A TCP socket that has not yet been converted to a `TcpStream` or cfg_net! {
/// `TcpListener`. /// A TCP socket that has not yet been converted to a `TcpStream` or
/// /// `TcpListener`.
/// `TcpSocket` wraps an operating system socket and enables the caller to ///
/// configure the socket before establishing a TCP connection or accepting /// `TcpSocket` wraps an operating system socket and enables the caller to
/// inbound connections. The caller is able to set socket option and explicitly /// configure the socket before establishing a TCP connection or accepting
/// bind the socket with a socket address. /// inbound connections. The caller is able to set socket option and explicitly
/// /// bind the socket with a socket address.
/// The underlying socket is closed when the `TcpSocket` value is dropped. ///
/// /// The underlying socket is closed when the `TcpSocket` value is dropped.
/// `TcpSocket` should only be used directly if the default configuration used ///
/// by `TcpStream::connect` and `TcpListener::bind` does not meet the required /// `TcpSocket` should only be used directly if the default configuration used
/// use case. /// by `TcpStream::connect` and `TcpListener::bind` does not meet the required
/// /// use case.
/// Calling `TcpStream::connect("127.0.0.1:8080")` is equivalent to: ///
/// /// Calling `TcpStream::connect("127.0.0.1:8080")` is equivalent to:
/// ```no_run ///
/// use tokio::net::TcpSocket; /// ```no_run
/// /// use tokio::net::TcpSocket;
/// use std::io; ///
/// /// use std::io;
/// #[tokio::main] ///
/// async fn main() -> io::Result<()> { /// #[tokio::main]
/// let addr = "127.0.0.1:8080".parse().unwrap(); /// async fn main() -> io::Result<()> {
/// /// let addr = "127.0.0.1:8080".parse().unwrap();
/// let socket = TcpSocket::new_v4()?; ///
/// let stream = socket.connect(addr).await?; /// let socket = TcpSocket::new_v4()?;
/// # drop(stream); /// let stream = socket.connect(addr).await?;
/// /// # drop(stream);
/// Ok(()) ///
/// } /// Ok(())
/// ``` /// }
/// /// ```
/// Calling `TcpListener::bind("127.0.0.1:8080")` is equivalent to: ///
/// /// Calling `TcpListener::bind("127.0.0.1:8080")` is equivalent to:
/// ```no_run ///
/// use tokio::net::TcpSocket; /// ```no_run
/// /// use tokio::net::TcpSocket;
/// use std::io; ///
/// /// use std::io;
/// #[tokio::main] ///
/// async fn main() -> io::Result<()> { /// #[tokio::main]
/// let addr = "127.0.0.1:8080".parse().unwrap(); /// async fn main() -> io::Result<()> {
/// /// let addr = "127.0.0.1:8080".parse().unwrap();
/// let socket = TcpSocket::new_v4()?; ///
/// // On platforms with Berkeley-derived sockets, this allows to quickly /// let socket = TcpSocket::new_v4()?;
/// // rebind a socket, without needing to wait for the OS to clean up the /// // On platforms with Berkeley-derived sockets, this allows to quickly
/// // previous one. /// // rebind a socket, without needing to wait for the OS to clean up the
/// // /// // previous one.
/// // On Windows, this allows rebinding sockets which are actively in use, /// //
/// // which allows “socket hijacking”, so we explicitly don't set it here. /// // On Windows, this allows rebinding sockets which are actively in use,
/// // https://docs.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse /// // which allows “socket hijacking”, so we explicitly don't set it here.
/// socket.set_reuseaddr(true)?; /// // https://docs.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse
/// socket.bind(addr)?; /// socket.set_reuseaddr(true)?;
/// /// socket.bind(addr)?;
/// let listener = socket.listen(1024)?; ///
/// # drop(listener); /// let listener = socket.listen(1024)?;
/// /// # drop(listener);
/// Ok(()) ///
/// } /// Ok(())
/// ``` /// }
/// /// ```
/// Setting socket options not explicitly provided by `TcpSocket` may be done by ///
/// accessing the `RawFd`/`RawSocket` using [`AsRawFd`]/[`AsRawSocket`] and /// Setting socket options not explicitly provided by `TcpSocket` may be done by
/// setting the option with a crate like [`socket2`]. /// accessing the `RawFd`/`RawSocket` using [`AsRawFd`]/[`AsRawSocket`] and
/// /// setting the option with a crate like [`socket2`].
/// [`RawFd`]: https://doc.rust-lang.org/std/os/unix/io/type.RawFd.html ///
/// [`RawSocket`]: https://doc.rust-lang.org/std/os/windows/io/type.RawSocket.html /// [`RawFd`]: https://doc.rust-lang.org/std/os/unix/io/type.RawFd.html
/// [`AsRawFd`]: https://doc.rust-lang.org/std/os/unix/io/trait.AsRawFd.html /// [`RawSocket`]: https://doc.rust-lang.org/std/os/windows/io/type.RawSocket.html
/// [`AsRawSocket`]: https://doc.rust-lang.org/std/os/windows/io/trait.AsRawSocket.html /// [`AsRawFd`]: https://doc.rust-lang.org/std/os/unix/io/trait.AsRawFd.html
/// [`socket2`]: https://docs.rs/socket2/ /// [`AsRawSocket`]: https://doc.rust-lang.org/std/os/windows/io/trait.AsRawSocket.html
pub struct TcpSocket { /// [`socket2`]: https://docs.rs/socket2/
pub struct TcpSocket {
inner: mio::net::TcpSocket, inner: mio::net::TcpSocket,
}
} }
impl TcpSocket { impl TcpSocket {