Skip to content

Commit 597bcec

Browse files
committed
Expanded top-level docs for std::net{TcpListener,TcpStream,UdpSocket}
Part of rust-lang#29363
1 parent ad816f8 commit 597bcec

File tree

2 files changed

+58
-9
lines changed

2 files changed

+58
-9
lines changed

src/libstd/net/tcp.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,25 @@ use sys_common::net as net_imp;
1717
use sys_common::{AsInner, FromInner, IntoInner};
1818
use time::Duration;
1919

20-
/// A structure which represents a TCP stream between a local socket and a
21-
/// remote socket.
20+
/// A TCP stream between a local and a remote socket.
2221
///
23-
/// The socket will be closed when the value is dropped.
22+
/// After creating a `TcpStream` by either [`connect`]ing to a remote host or
23+
/// [`accept`]ing a connection on a [`TcpListener`], data can be transmitted
24+
/// by [reading] and [writing] to it.
25+
///
26+
/// The connection will be closed when the value is dropped. The reading and writing
27+
/// portions of the connection can also be shut down individually with the [`shutdown`]
28+
/// method.
29+
///
30+
/// The Transmission Control Protocol is specified in [IETF RFC 793].
31+
///
32+
/// [`accept`]: ../../std/net/struct.TcpListener.html#method.accept
33+
/// [`connect`]: #method.connect
34+
/// [IETF RFC 793]: https://tools.ietf.org/html/rfc793
35+
/// [reading]: ../../std/io/trait.Read.html
36+
/// [`shutdown`]: #method.shutdown
37+
/// [`TcpListener`]: ../../std/net/struct.TcpListener.html
38+
/// [writing]: ../../std/io/trait.Write.html
2439
///
2540
/// # Examples
2641
///
@@ -39,7 +54,21 @@ use time::Duration;
3954
#[stable(feature = "rust1", since = "1.0.0")]
4055
pub struct TcpStream(net_imp::TcpStream);
4156

42-
/// A structure representing a socket server.
57+
/// A TCP socket server, listening for connections.
58+
///
59+
/// After creating a `TcpListener` by [`bind`]ing it to a socket address, it listens
60+
/// for incoming TCP connections. These can be accepted by calling [`accept`] or by
61+
/// iterating over the [`Incoming`] iterator returned by [`incoming`].
62+
///
63+
/// The socket will be closed when the value is dropped.
64+
///
65+
/// The Transmission Control Protocol is specified in [IETF RFC 793].
66+
///
67+
/// [`accept`]: #method.accept
68+
/// [`bind`]: #method.bind
69+
/// [IETF RFC 793]: https://tools.ietf.org/html/rfc793
70+
/// [`Incoming`]: ../../std/net/struct.Incoming.html
71+
/// [`incoming`]: #method.incoming
4372
///
4473
/// # Examples
4574
///

src/libstd/net/udp.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,29 @@ use sys_common::net as net_imp;
1515
use sys_common::{AsInner, FromInner, IntoInner};
1616
use time::Duration;
1717

18-
/// A User Datagram Protocol socket.
18+
/// A UDP socket.
1919
///
20-
/// This is an implementation of a bound UDP socket. This supports both IPv4 and
21-
/// IPv6 addresses, and there is no corresponding notion of a server because UDP
22-
/// is a datagram protocol.
20+
/// After creating a `UdpSocket` by [`bind`]ing it to a socket address, data can be
21+
/// [sent to] and [received from] any other socket address.
22+
///
23+
/// Although UDP is a connectionless protocol, this implementation provides an interface
24+
/// to set an address where data should be sent and received from. After setting a remote
25+
/// address with [`connect`], data can be sent to and received from that address with
26+
/// [`send`] and [`recv`].
27+
///
28+
/// As stated in the User Datagram Protocol's specification in [IETF RFC 768], UDP is
29+
/// an unordered, unreliable protocol; refer to [`TcpListener`] and [`TcpStream`] for TCP
30+
/// primitives.
31+
///
32+
/// [`bind`]: #method.bind
33+
/// [`connect`]: #method.connect
34+
/// [IETF RFC 768]: https://tools.ietf.org/html/rfc768
35+
/// [`recv`]: #method.recv
36+
/// [received from]: #method.recv_from
37+
/// [`send`]: #method.send
38+
/// [sent to]: #method.send_to
39+
/// [`TcpListener`]: ../../std/net/struct.TcpListener.html
40+
/// [`TcpStream`]: ../../std/net/struct.TcpStream.html
2341
///
2442
/// # Examples
2543
///
@@ -582,9 +600,11 @@ impl UdpSocket {
582600
/// Receives data on the socket from the remote address to which it is
583601
/// connected.
584602
///
585-
/// The `connect` method will connect this socket to a remote address. This
603+
/// The [`connect`] method will connect this socket to a remote address. This
586604
/// method will fail if the socket is not connected.
587605
///
606+
/// [`connect`]: #method.connect
607+
///
588608
/// # Examples
589609
///
590610
/// ```no_run

0 commit comments

Comments
 (0)