I've read the documentation for std::net
and mio, and I've found some methods like set_nodelay
and set_keepalive
, but I haven't found a way to set other socket options like SO_REUSEPORT
and SO_REUSEADDR
on a given socket. How can I do this?
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Share Arc between closures
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
Because
SO_REUSEPORT
isn't cross-platform, you will need to dip into platform-specific code. In this case, you can get the raw file descriptor from the socket and then use functions, types, and values from the libc crate to set the options you want:I make no guarantee that this is the right place to set this option, or that I haven't screwed up something in the unsafe block, but it does compile and run on macOS 10.12.
A better solution may be to check out the nix crate, which provides nicer wrappers for most *nix-specific code:
An even better solution may be to check out the net2 crate, which provides higher-level methods aimed specifically at networking-related code: