Comments (6)
Thanks for the explanation and the thorough issue report! I suspect that the bindings here are pretty simple so I think they'd work well in this crate. In general this crate is "mostly single-line wrappers around system functionality", so as long as it fits that bill it should be good to add.
from socket2.
Hi @alexcrichton, thanks for the comment. I've started exploring the design space and doing something usable across platforms required many lines of unsafe code.
I've started to do that on a fork of socket2, but as it kept growing I felt like it would be a bit too big for the project. So I've moved those out to a new crate using some of the OS-specific traits to get access to the socket handle, which was great!
I've put the functionality on multicast-socket, and maybe there are a few things that could be added back here, such as socket.set_pktinfo(true)
, or exposing to_s_addr
, which would help me reduce some copy-and-paste.
The actual sendmsg
and recvmsg
seems to be a bit more complex to be packaged as cross-patform generic code while trying to be a "single-line wrapper" and I wonder if it would be worth extracting out.
Thanks a lot for providing the AsRawFd
and AsRawSocket
crate, which allowed to access the underlying handler to wrap things on that nice little crate :) I've tested it on Android, Windows, Linux, Mac and even MIPS and I can do mdns discovery now!
Feel free to either close the issue or suggest any of the code to be contributed back that fits project. Thanks for the attention!
from socket2.
@bltavares what concretely has to be done to solve this issue? In other words what is socket2 missing (on the master branch)?
from socket2.
I think we could close the issue, as it is already possible to use the AsRawFd
to access things from a socket2::Socket
, but there are a few things that could be ported over to socket2, but I'm not sure if that is the intention of the crate.
- Expose to_s_addr to avoid copy-and-paste
- Add
socket.set_pkt_info(true)
that wraps this piece similarly to howsocket.set_reuse_address(true)
works - A more generic way to find socket extensions, such as WSARecvMsgExtension on windows
- A
socket.bind_multicast
which abstracts the differences between platforms - Expose recvmsg, and sendmsg (and on windows, the equivalents from an extension method WSA*) to be able to make syscalls with more extensions
This is not required to work, more of a list of ideas when using socket2 on this specific use-case. Given the crate can be used through the AsRawFd
trait I would be ok to close this issue and only pick some of the ideas that match the crate goal :)
from socket2.
I think we could close the issue, as it is already possible to use the
AsRawFd
to access things from asocket2::Socket
, but there are a few things that could be ported over to socket2, but I'm not sure if that is the intention of the crate.* Expose [to_s_addr](https://github.com/bltavares/multicast-socket/blob/d62ec76551b050364bacf4f9540492279644077c/src/win.rs#L443-L449) to avoid copy-and-paste
Is SockAddr::{family, len, as_ptr}
sufficient for this?
Lines 65 to 78 in 9c4a404
* Add `socket.set_pkt_info(true)` that wraps [this piece](https://github.com/bltavares/multicast-socket/blob/d62ec76551b050364bacf4f9540492279644077c/src/win.rs#L443-L449) similarly to how `socket.set_reuse_address(true)` works
A pr for this would definitely be accepted.
* A more generic way to find socket extensions, such as [WSARecvMsgExtension](https://github.com/bltavares/multicast-socket/blob/d62ec76551b050364bacf4f9540492279644077c/src/win.rs#L150) on windows * A `socket.bind_multicast` which abstracts [the differences between platforms](https://github.com/bltavares/multicast-socket/blob/d62ec76551b050364bacf4f9540492279644077c/src/win.rs#L158-L160)
These would be a bit harder but we can work on it. At the very least we could expose the OS specific functions.
* Expose [recvmsg](https://github.com/bltavares/multicast-socket/blob/d62ec76551b050364bacf4f9540492279644077c/src/unix.rs), and [sendmsg](https://github.com/bltavares/multicast-socket/blob/d62ec76551b050364bacf4f9540492279644077c/src/unix.rs#L184) (and on windows, the equivalents from [an extension method WSA*](https://github.com/bltavares/multicast-socket/blob/d62ec76551b050364bacf4f9540492279644077c/src/win.rs#L306)) to be able to make syscalls with more extensions
We expose Socket::recv_with_flags
:
Lines 318 to 328 in 9c4a404
And Socket::recv_vectored_with_flags
:
Lines 363 to 381 in 9c4a404
Or do you need access to msghdr
structure?
from socket2.
- There is a similar crate that do this a-ba/udp_sas.
from socket2.
Related Issues (20)
- Add CI support for ESP-IDF
- msghdr as a private field in MsgHdr/MsgMutHdr HOT 2
- Set Socket interface using interface index HOT 1
- What happened to the `RAW` socket type? HOT 1
- Question: Possible to support architectures that only provide the `std::net` interface (and only TCP)? HOT 4
- Windows: `sa_family_t` should use `ADDRESS_FAMILY` from `windows-sys` HOT 5
- nonblocking connect HOT 6
- Set `ss_len` when creating `SockAddr` from std HOT 1
- Why cannot find WASStartup and WSACleanup in source code? HOT 7
- bind_device succeeds, but subsequent sends fail with no such device or address. HOT 5
- QUESTION: How to special `laddr` when dialing connection? HOT 3
- Android support HOT 3
- don'tassign8080 port
- Currently socket2 has no way to set the DF bit on packets. The attached patch adds it. HOT 3
- Error: BoxSend(Os { code: 98, kind: AddrInUse, message: "Address already in use" }) HOT 2
- How to read EventExtra from the event? HOT 2
- socket() always fails on WSL1 due to unsupported SOCK_CLOEXEC flag HOT 5
- Support for {recv,send}mmsg HOT 2
- New release HOT 1
- socket error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from socket2.