Repository: tokio-rs/tokio
File: tokio/src/io/interest.rs (Rust)

Code before:
        #[cfg(any(target_os = "linux", target_os = "android"))]
        if self.is_priority() {
            mio |= mio::Interest::PRIORITY;
        }

        #[cfg(target_os = "freebsd")]
        if self.is_aio() {
            mio |= mio::Interest::AIO;
        }

        #[cfg(target_os = "freebsd")]
        if self.is_lio() {
            mio |= mio::Interest::LIO;
        }

        // Finally remove the starting value unless either:
        //
        // - the readable interest is specified
        // - the error interest is specified. There is no error interest in mio, because error
        //    events are always reported. But mio interests cannot be empty and one is needed
        //    just for the registeration.
        //
        //    read readiness is filtered out in `Interest::mask` or `Ready::from_interest` if
        //    needed
        if !self.is_readable() && !self.is_error() {
            mio.remove(mio::Interest::READABLE);
        }

        mio
    }

    pub(crate) fn mask(self) -> Ready {
        match self {
            Interest::READABLE => Ready::READABLE | Ready::READ_CLOSED,
            Interest::WRITABLE => Ready::WRITABLE | Ready::WRITE_CLOSED,
            #[cfg(any(target_os = "linux", target_os = "android"))]
            Interest::PRIORITY => Ready::PRIORITY | Ready::READ_CLOSED,
            Interest::ERROR => Ready::ERROR,
            _ => Ready::EMPTY,
        }
    }
}

impl ops::BitOr for Interest {
    type Output = Self;

    #[inline]
    fn bitor(self, other: Self) -> Self {
        self.add(other)
    }
}

Review comment (bug):
This is incorrect.
```suggestion
            mio = mio.remove(mio::Interest::READABLE);
```

Code after:
            mio_add(&mut mio, mio::Interest::READABLE);
        }

        if self.is_writable() {
            mio_add(&mut mio, mio::Interest::WRITABLE);
        }

        #[cfg(any(target_os = "linux", target_os = "android"))]
        if self.is_priority() {
            mio_add(&mut mio, mio::Interest::PRIORITY);
        }

        #[cfg(target_os = "freebsd")]
        if self.is_aio() {
            mio_add(&mut mio, mio::Interest::AIO);
        }

        #[cfg(target_os = "freebsd")]
        if self.is_lio() {
            mio_add(&mut mio, mio::Interest::LIO);
        }

        if self.is_error() {
            // There is no error interest in mio, because error events are always reported.
            // But mio interests cannot be empty and an interest is needed just for the registeration.
            //
            // read readiness is filtered out in `Interest::mask` or `Ready::from_interest` if
            // the read interest was not specified by the user.
            mio_add(&mut mio, mio::Interest::READABLE);
        }

        // the default `mio::Interest::READABLE` should never be used in practice. Either
        //
        // - at least one tokio interest with a mio counterpart was used
        // - only the error tokio interest was specified
        //
        // in both cases, `mio` is Some already
        mio.unwrap_or(mio::Interest::READABLE)
    }

    pub(crate) fn mask(self) -> Ready {
        match self {
            Interest::READABLE => Ready::READABLE | Ready::READ_CLOSED,
            Interest::WRITABLE => Ready::WRITABLE | Ready::WRITE_CLOSED,
            #[cfg(any(target_os = "linux", target_os = "android"))]
            Interest::PRIORITY => Ready::PRIORITY | Ready::READ_CLOSED,
            Interest::ERROR => Ready::ERROR,
            _ => Ready::EMPTY,
        }
    }
}