2 ms·
The thing I don't get is why Rust sockets have a `set_nonblocking()` function at all. Should there just be separate`recv_blocking()` and `recv_nonblocking()` fu
by IshKebab 10y ago
The thing I don't get is why Rust sockets have a `set_nonblocking()` function at all. Should there just be separate`recv_blocking()` and `recv_nonblocking()` functions? It would be much simpler. Sadly you can't even do your own interface like that because there is no `get_nonblocking()` function.
Also is HN ever going to support markdown?
- steveklabnik 10y agoThe standard library's abstractions tend to be relatively thin mappers over OS functionality: https://doc.rust-lang.org/stable/std/net/struct.UdpSocket.html#method.set_nonblocking https://doc.rust-lang.org/stable/std/net/struct.UdpSocket.ht... So, in my understanding, it has this interface because that's the interface that the OS gives you. Why couldn't you write this interface on top? You'd be writing that function yourself, no?
- valarauca1 10y agoIn Unix you don't get a choice to block on one or the other. You just get a non-blocking File Descriptor. To add this you'd need to iron bandage system calls during compilation depending on which calls were made, and their order they were made. The alternative is having an Epoll/Kqueue loop run until one or another happen. But that's still a lot of magic and resource consumption behind the scenes for a language that offers low level control.