Skip to content
This repository was archived by the owner on May 17, 2018. It is now read-only.

Commit 2e2bdfc

Browse files
committed
Tweak methods and docs before release
1 parent 469d92f commit 2e2bdfc

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/lib.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ impl fmt::Debug for UnixDatagram {
665665
}
666666

667667
impl UnixDatagram {
668-
/// Creates a Unix datagram socket from the given path.
668+
/// Creates a Unix datagram socket bound to the given path.
669669
pub fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixDatagram> {
670670
unsafe {
671671
let inner = try!(Inner::new(libc::SOCK_DGRAM));
@@ -679,19 +679,19 @@ impl UnixDatagram {
679679
}
680680
}
681681

682-
/// Creates a Unix Datagram socket which is not bound to any address
683-
/// you may use send_to to send message (but probably can't receive)
684-
pub fn new() -> io::Result<UnixDatagram> {
682+
/// Creates a Unix Datagram socket which is not bound to any address.
683+
pub fn unbound() -> io::Result<UnixDatagram> {
685684
let inner = try!(Inner::new(libc::SOCK_DGRAM));
686685
Ok(UnixDatagram {
687686
inner: inner,
688687
})
689688
}
690689

691-
/// Creates a Unix Datagram socket which is connected to specified addresss
692-
/// the socket is unnamed and similar to one created by `new()` except
693-
/// it will send message to the specified addresss *by default*
694-
pub fn connect<P: AsRef<Path>>(&mut self, path: P)
690+
/// Connect the socket to the specified address.
691+
///
692+
/// The `send` method may be used to send data to the specified address.
693+
/// `recv` and `recv_from` will only receive data from that address.
694+
pub fn connect<P: AsRef<Path>>(&self, path: P)
695695
-> io::Result<()>
696696
{
697697
unsafe {
@@ -731,18 +731,18 @@ impl UnixDatagram {
731731

732732
/// Receives data from the socket.
733733
///
734-
/// On success, returns the number of bytes read
734+
/// On success, returns the number of bytes read.
735735
pub fn recv(&self, buf: &mut [u8]) -> io::Result<usize> {
736736
unsafe {
737737
let count = try!(cvt_s(libc::recv(self.inner.0,
738-
buf.as_mut_ptr() as *mut _,
739-
calc_len(buf),
740-
0)));
738+
buf.as_mut_ptr() as *mut _,
739+
calc_len(buf),
740+
0)));
741741
Ok(count as usize)
742742
}
743743
}
744744

745-
/// Sends data on the socket to the given address.
745+
/// Sends data on the socket to the specified address.
746746
///
747747
/// On success, returns the number of bytes written.
748748
pub fn send_to<P: AsRef<Path>>(&self, buf: &[u8], path: P) -> io::Result<usize> {
@@ -759,9 +759,10 @@ impl UnixDatagram {
759759
}
760760
}
761761

762-
/// Sends data on the socket to the default address.
762+
/// Sends data on the socket to the socket's peer.
763763
///
764-
/// Default address is set when socket was created by `connect()` constructor
764+
/// The peer address may be set by the `connect` method, and this method
765+
/// will return an error if the socket has not already been connected.
765766
///
766767
/// On success, returns the number of bytes written.
767768
pub fn send(&self, buf: &[u8]) -> io::Result<usize> {
@@ -1103,7 +1104,7 @@ mod test {
11031104
let path1 = dir.path().join("sock1");
11041105

11051106
let sock1 = or_panic!(UnixDatagram::bind(&path1));
1106-
let sock2 = or_panic!(UnixDatagram::new());
1107+
let sock2 = or_panic!(UnixDatagram::unbound());
11071108

11081109
let msg = b"hello world";
11091110
or_panic!(sock2.send_to(msg, &path1));
@@ -1122,7 +1123,7 @@ mod test {
11221123

11231124
let bsock1 = or_panic!(UnixDatagram::bind(&path1));
11241125
let bsock2 = or_panic!(UnixDatagram::bind(&path2));
1125-
let mut sock = or_panic!(UnixDatagram::new());
1126+
let sock = or_panic!(UnixDatagram::unbound());
11261127
or_panic!(sock.connect(&path1));
11271128

11281129
// Check send()
@@ -1153,7 +1154,7 @@ mod test {
11531154
let path1 = dir.path().join("sock1");
11541155

11551156
let sock1 = or_panic!(UnixDatagram::bind(&path1));
1156-
let mut sock2 = or_panic!(UnixDatagram::new());
1157+
let sock2 = or_panic!(UnixDatagram::unbound());
11571158
or_panic!(sock2.connect(&path1));
11581159

11591160
let msg = b"hello world";

0 commit comments

Comments
 (0)