[ I suspect the following might have already been discussed long time ago, I'm sorry if I'm repeating something everyone already knew. If there is already an existing conclusion about this, please let me know, thanks. ]
There have been many questions asked about the future of std::net
, and there have been real efforts to replace it (or amend it?) such as net2
crate (deprecated) and socket2
crate, not to mention crates like nix
to cover sockets too, only the Unix platforms.
After using std::net
, socket2
and nix
on macOS, Linux and Windows, it seems to me that a couple of weak spots of std::net
are:
- Its API does not support custom operations (i.e.
setsockopt
) before callingbind()
. - It does not expose a
Socket
struct or trait because this name is already defined as platform-dependent.
Clearly these two points are related. Inspired by an old RFC issue, I was wondering if there have been any effort to add a SocketBuilder
in std::net
?
Similar to what mentioned in the linked old issue, SocketBuilder
would:
- Wrap around a platform-dependent
Socket
to present a platform-independent socket interface as close to a traditional socket as possible. - Allow custom operations before calling
bind()
on the inner socket.
In addition, the existing struct can be updated to support SocketBuilder
as well, for example, UdpSocket
can have a new method like : bind_builder(builder: SocketBuilder) -> io::Result<UdpSocket>
. This allows the apps to continue using UdpSocket
as the main API.
Is there a plan for a RFC / pre-RFC about enhancing std::net
to allow custom operations before calling bind()
or somehow exposing a socket
based API?
Thanks!