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

Add MSG_PEEK socket flag #492

Merged
merged 1 commit into from
Jan 10, 2017
Merged

Conversation

APTy
Copy link

@APTy APTy commented Jan 10, 2017

MSG_PEEK

This PR exposes a cross-platform MSG_PEEK flag that a user may pass into the flags parameter for recv(), recvfrom(), or recvmsg() calls.

   MSG_PEEK
          This flag causes the receive operation to return data from the
          beginning of the receive queue without removing that data from the
          queue.  Thus, a subsequent receive call will return the same data.

In short, users may call recv() to "peek" at new data (or a message) without consuming it. Recall that in the normal case, calls to recv() consume the data from the socket's receive queue, making it unavailable to future calls.

Motivation

This change enables libc users, such as the rust standard library, to potentially add peeking functionality to TCP and UDP implementations, like TcpStream and UdpSocket, without being concerned about the highly platform-dependent nature of the flags.

(In this case, the flag's value 0x2 is very consistent, but that is not the case for many of the MSG_* flags. It makes sense to keep these differences confined to libc)

Reference

bsd/apple: socket.h
bsd/freebsdlike/freebsd: socket.h
bsd/freebsdlike/dragonfly: socket.h
bsd/netbsdlike: socket.h
unix/haiku: socket.h
unix/notbsd/linux: socket.h
unix/notbsd/android: socket.h

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton
Copy link
Member

@bors: r+

Thanks!

@bors
Copy link
Contributor

bors commented Jan 10, 2017

📌 Commit b619df8 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jan 10, 2017

⌛ Testing commit b619df8 with merge 33ff832...

bors added a commit that referenced this pull request Jan 10, 2017
Add MSG_PEEK socket flag

#### MSG_PEEK
This PR exposes a cross-platform `MSG_PEEK` flag that a user may pass into the `flags` parameter for `recv()`, `recvfrom()`, or `recvmsg()` calls.

```
   MSG_PEEK
          This flag causes the receive operation to return data from the
          beginning of the receive queue without removing that data from the
          queue.  Thus, a subsequent receive call will return the same data.
```

In short, users may call `recv()` to "peek" at new data (or a message) without consuming it. Recall that in the normal case, calls to `recv()` consume the data from the socket's receive queue, making it unavailable to future calls.

#### Motivation
This change enables `libc` users, such as the rust standard library, to potentially add peeking functionality to TCP and UDP implementations, like `TcpStream` and `UdpSocket`, without being concerned about the highly platform-dependent nature of the flags.

(In this case, the flag's value `0x2` is very consistent, but that is not the case for many of the `MSG_*` flags. It makes sense to keep these differences confined to `libc`)

#### Reference
[bsd/apple: socket.h](https://opensource.apple.com/source/xnu/xnu-2050.7.9/bsd/sys/socket.h)
[bsd/freebsdlike/freebsd: socket.h](https://github.com/freebsd/freebsd/blob/master/sys/sys/socket.h#L418)
[bsd/freebsdlike/dragonfly: socket.h](https://github.com/DragonFlyBSD/DragonFlyBSD/blob/1f249c981c4e89e7cde1836a75b61cac36dc7ac5/sys/sys/socket.h#L367)
[bsd/netbsdlike: socket.h](https://github.com/IIJ-NetBSD/netbsd-src/blob/af5d253140491f2d1816c59ecb8a4d8a8d927688/sys/sys/socket.h#L517)
[unix/haiku: socket.h](https://github.com/haiku/haiku/blob/b65adbdfbc322bb7d86d74049389c688e9962f15/headers/posix/sys/socket.h#L114)
[unix/notbsd/linux: socket.h](https://github.com/torvalds/linux/blob/5924bbecd0267d87c24110cbe2041b5075173a25/include/linux/socket.h#L264)
[unix/notbsd/android: socket.h](https://android.googlesource.com/platform/development/+/73a5a3baaa5089f1ab2049e5934fa5d8a3f3e76a/ndk/platforms/android-20/include/sys/socket.h#229)
@bors
Copy link
Contributor

bors commented Jan 10, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 33ff832 to master...

@bors bors merged commit b619df8 into rust-lang:master Jan 10, 2017
Susurrus pushed a commit to Susurrus/libc that referenced this pull request Mar 26, 2017
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.

4 participants