I am a newcomer of Rust, I have learned that there is a variety of features in std, but why except raw socket? Many programming language like Python, Go have raw socket features in their std and worked well, why doesn't Rust make one and add to its std?
Of course there is at least one raw socket crate for Rust: https://github.com/szymonwieloch/rust-rawsock
The question then is why not include in std:: ?
If I understand correctly the idea is to keep Rust's std:: as small as possible. Which lessens the burden on the core dev team and lessons the chance of bad API's getting frozen into std:: forever. As we see in C for example.
So the question is then: Why should such a library be in std::. External crates work, and they will be around forever, even if better alternatives get developed over time.
I think raw sockets are OS specific, eg:
That's a different usage of the term "raw socket". Windows raw sockets are I/O devices that represents an underlying transport such as TCP, UDP, or a networking raw socket (as TCP and UDP is implemented in kernel space). I think OP was asking about networking raw sockets - there aren't currently any functions in std that expose a Windows raw socket or Unix raw file descriptor that represents a networking raw socket.
There is raw socket for Windows, indeed, but it just only for Windows, not for Linux, it is not cross-platformed.
But should it be, given that the raw system APIs are quite different? For common cases in cross-platform development, like TCP, there are more high-level wrappers, which encapsulate the platform differences.
hmm, but as far as I know, in Windows and Linux platform, raw socket, UDP and TCP are all socket, so I think encapsulate raw socket should be the same to UDP and TCP?
What's more, raw socket was included in Python and Go's std, they are also cross-platform language, aren't they?
In Unix-like systems, everything is a file, including sockets, so the way to get raw access to a socket would be to convert it to a file descriptor with
AsRawFd. From what I understand, Windows distinguishes files and sockets, so there are separate
AsRawSocket traits for Windows. In both cases the interface is fairly low-level, but Rust is fairly conservative about what goes in its standard library, so higher level abstractions are likely to be in other crates. I suppose raw sockets are also somewhat less commonly used than TCP or UDP sockets, so that may be a factor in why they haven't been given standard library wrappers.
Oh, I probably confused std::os:windows::io::RawSocket with SOCK_RAW type socket .I mean the latter, not how to operate socket in Unix-like system, Sorry.
Note that the
socket2 library was recently moved to the rust-lang github organization.