-
Notifications
You must be signed in to change notification settings - Fork 684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Non-blocking on macOS / iOS #861
Comments
First off, your welcome! Hopefully even with this missing/unknown functionality you've found Unfortunately Additionally, if the functionality you need isn't available in |
@Susurrus I understand that you are trying to be professional in your answer. I know there is a lot of work to be done with both pub fn socket<T: Into<Option<SockProtocol>>>(domain: AddressFamily, ty: SockType, flags: SockFlag, protocol: T) -> Result<RawFd> { has a giant cfg gate on it that doesn't support macOS even though macOS does support OFlag::O_NONBLOCK In 0.9.0 it was okay to use I will attempt to write a PR and look for your help. Thanks. For anyone who hits this via google, etc. you will have to set it manually until this gets resolved: use libc;
use nix;
use std::io;
/*
cvt from mio lib
https://github.com/carllerche/mio/blob/91f0832036303c7f83c286e049e31be29c43b519/src/sys/unix/mod.rs#L71
*/
trait IsMinusOne {
fn is_minus_one(&self) -> bool;
}
impl IsMinusOne for i32 {
fn is_minus_one(&self) -> bool { *self == -1 }
}
impl IsMinusOne for isize {
fn is_minus_one(&self) -> bool { *self == -1 }
}
fn cvt<T: IsMinusOne>(t: T) -> ::io::Result<T> {
use std::io;
if t.is_minus_one() {
Err(io::Error::last_os_error())
} else {
Ok(t)
}
}
pub fn set_nonblock(fd: libc::c_int) -> io::Result<()> {
unsafe {
let flags = libc::fcntl(fd, libc::F_GETFL);
cvt(libc::fcntl(fd, libc::F_SETFL, flags | libc::O_NONBLOCK)).map(|_|())
}
}
pub fn set_cloexec(fd: libc::c_int) -> io::Result<()> {
unsafe {
let flags = libc::fcntl(fd, libc::F_GETFD);
cvt(libc::fcntl(fd, libc::F_SETFD, flags | libc::FD_CLOEXEC)).map(|_| ())
}
}
/* setup your socket */
let fd: RawFd = socket( AddressFamily::System,
SockType::Datagram,
SockFlag::empty(),
SockProtocol::KextControl )?;
set_nonblock(fd)?;
set_cloexec(fd)?; |
You weren't clear in your original question, both here and in the other PR or issue you commented on, so I wasn't sure if a) it should work on mac/ios and doesn't or b) you weren't sure how these APIs worked at all. I assumed it was b because of the way you phrased it originally. If it's indeed a), especially if it's a feature regression, we'd definitely welcome a PR fixing it! No need to reopen this issue, however, if you're going to file a PR though. |
…LOEXEC` on macos and ios; ref nix-rust#244 nix-rust#861
…gate on `test_sockflag_cloexec`; ref nix-rust#244 nix-rust#861
Thanks to everyone for your hard work.
nix::sys::socket::socket
provides a fourth parameter that ends-up callingfcntl()
and friends but seemingly does not support macos.What is the best way to open a non-blocking socket on macos/ios using nix?
ref: https://github.com/nix-rust/nix/blob/v0.10.0/src/sys/socket/mod.rs#L684-L718
The text was updated successfully, but these errors were encountered: