Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unix socket doc #38236

Merged
merged 5 commits into from
Dec 21, 2016
Merged

Unix socket doc #38236

merged 5 commits into from
Dec 21, 2016

Conversation

GuillaumeGomez
Copy link
Member

///
/// ```
///
/// ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example doesn't seem particularly helpful :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh damn!

/// ```
/// use std::os::unix::net::UnixListener;
///
/// let socket = match UnixListener::bind("/tmp/sock") {
Copy link
Member

@nagisa nagisa Dec 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO every single example exhaustively matching on socket creation is sort of overzealous.

if let Ok(socket) = UnixListener::bind("/tmp/sock") {
     // show off the feature
}

would be a much better alternative IMO.

EDIT: exhaustive matching is fine on the examples of functions that do the actual socket creation, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll just go for unwrap for the other cases.

/// ```no_run
/// use std::os::unix::net::UnixStream;
///
/// let socket = match UnixStream::connect("/tmp/sock") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused variable :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see it as an issue here, on the opposite. The point is to show people how it works, and creating a (unused) variable helps it.

/// let (sock1, sock2) = match UnixStream::pair() {
/// Ok((sock1, sock2)) => (sock1, sock2),
/// Err(e) => {
/// println!("Couldn't connect: {:?}", e);
Copy link
Member

@nagisa nagisa Dec 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn’t create a pair of sockets.

@GuillaumeGomez
Copy link
Member Author

Updated.

@GuillaumeGomez GuillaumeGomez force-pushed the unix_socket_doc branch 2 times, most recently from 477ba42 to fdbd760 Compare December 9, 2016 06:28
@GuillaumeGomez
Copy link
Member Author

And urls fixed as well. Build fails but doesn't have errors so I guess it's okay?

Copy link
Member

@frewsxcv frewsxcv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few comments 🎊

/// use std::os::unix::net::UnixStream;
///
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
/// socket.set_nonblocking(true).expect("Couldn't set non blocking");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: 'nonblocking' is one word

/// use std::os::unix::net::UnixDatagram;
///
/// let sock = UnixDatagram::unbound().unwrap();
/// sock.send_to(b"omelette AU fromage", "/some/sock").expect("send_to function failed");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: why is "AU" capitalized?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To help english people improve their french. :p

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, a person who doesn't know any French, it doesn't help me learn French, it just makes me confused :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha. Well, I'll "fixed" it then.

///
/// let sock = UnixDatagram::unbound().unwrap();
/// sock.connect("/some/sock").expect("Couldn't connect");
/// sock.send(b"omelette AU fromage").expect("send_to function failed");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto "AU"

/// let socket = UnixListener::bind("/tmp/sock").unwrap();
/// let addr = socket.local_addr().expect("Couldn't get local address");
/// assert_eq!(addr.is_unnamed(), false);
/// ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an example here where is_unnamed() is true?

/// let socket = UnixListener::bind("/tmp/sock").unwrap();
/// let addr = socket.local_addr().expect("Couldn't get local address");
/// assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/sock")));
/// ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. If we can create an unnamed socket, can we show here that as_pathname() is None?

@GuillaumeGomez
Copy link
Member Author

Updated.

Copy link
Member

@frewsxcv frewsxcv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me unless you want to address the nits

/// let addr = socket.local_addr().expect("Couldn't get local address");
/// assert_eq!(addr.is_unnamed(), false);
///
/// // with is_unnamed() as true now:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Alternatively, you could also do something like this:

# Examples

An unnamed address:

```
...
```

A named address:

```
...
```

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good point!

/// use std::os::unix::net::UnixStream;
///
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
/// let sock_copy = socket.try_clone().expect("Couldn't clone socket...");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The ellipsis here doesn't seem necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ellipsis? What do you mean? The expect call?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GuillaumeGomez
Copy link
Member Author

I addressed the nits.

/// let addr = socket.local_addr().expect("Couldn't get local address");
/// assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/sock")));
///
/// // with as_pathname() as true now:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want to do the same thing here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh indeed!

@frewsxcv
Copy link
Member

r=me unless you want to address that comment

@GuillaumeGomez
Copy link
Member Author

And updated too.

@frewsxcv
Copy link
Member

@bors r+ rollup 🎉

@bors
Copy link
Contributor

bors commented Dec 13, 2016

📌 Commit cc180fb has been approved by frewsxcv

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Dec 15, 2016
@frewsxcv
Copy link
Member

@bors r-

Errors: #38387 (comment)

@GuillaumeGomez
Copy link
Member Author

And fixed. I re-r+ if you don't mind @frewsxcv.

@bors: r=frewsxcv

@bors
Copy link
Contributor

bors commented Dec 16, 2016

📌 Commit 2938e6a has been approved by frewsxcv

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Dec 16, 2016
@bors
Copy link
Contributor

bors commented Dec 16, 2016

⌛ Testing commit 2938e6a with merge 1ca362c...

@bors
Copy link
Contributor

bors commented Dec 16, 2016

💔 Test failed - auto-mac-64-opt-rustbuild

@GuillaumeGomez
Copy link
Member Author

@bors: retry

@bors
Copy link
Contributor

bors commented Dec 16, 2016

⌛ Testing commit 2938e6a with merge 92039a2...

@bors
Copy link
Contributor

bors commented Dec 16, 2016

💔 Test failed - auto-mac-64-opt-rustbuild

@alexcrichton
Copy link
Member

alexcrichton commented Dec 16, 2016 via email

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Dec 18, 2016
@sanxiyn
Copy link
Member

sanxiyn commented Dec 19, 2016

@bors retry

@alexcrichton
Copy link
Member

@bors: retry

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Dec 20, 2016
bors added a commit that referenced this pull request Dec 20, 2016
@bors bors merged commit 2938e6a into rust-lang:master Dec 21, 2016
@GuillaumeGomez GuillaumeGomez deleted the unix_socket_doc branch December 21, 2016 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants