Why does sys::unix::fd::FileDesc::set_nonblocking use FIONBIO instead of O_NONBLOCK?

I have been looking at sys::unix::fd extensively as I am forced to reimplement parts of it for a project.

One thing that stuck out to me is the use of ioctl FIONBIO to set nonblocking mode on Linux specifically.

From my understanding, FIONBIO is old and was superceded by POSIX in the form of O_NONBLOCK

This is counter to how set_cloexec is implemented, which uses the newer (and POSIX) FD_CLOEXEC

Is there a rationale for this?

I think this is strange, especially as it does use O_NONBLOCK on other UNIX-ish operating systems. As far as I know FIONBIO are and O_NONBLOCK are handled exactly the same on Linux.

If this is intentional then I think it's because it's one system call instead of two. Requiring only one round-trip to the kernel is a little bit faster.

On other Unix FIONBIO might do something different so the same "trick" cannot be used.

Looks like this indeed was the reasoning when the change was done: Use less syscalls in `FileDesc::set_{nonblocking,cloexec}` · rust-lang/rust@efeb42b · GitHub

Ah. I suspected it was just to avoid extraneous syscalls, but the lack of comments made it unclear. Thanks!