-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
SO_NOSIGPIPE and MSG_NOSIGNAL (rebased #36426) #36824
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
+1 −0 | libc-test/build.rs | |
+2 −0 | src/unix/mod.rs | |
+17 −0 | src/unix/notbsd/linux/mod.rs | |
+2 −0 | src/unix/notbsd/mod.rs |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,14 @@ use libc::SOCK_CLOEXEC; | |
#[cfg(not(target_os = "linux"))] | ||
const SOCK_CLOEXEC: c_int = 0; | ||
|
||
// Another conditional contant for name resolution: Macos et iOS use | ||
// SO_NOSIGPIPE as a setsockopt flag to disable SIGPIPE emission on socket. | ||
// Other platforms do otherwise. | ||
#[cfg(target_vendor = "apple")] | ||
use libc::SO_NOSIGPIPE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Android is covered by target_os="linux", and the value is correct. I don't have easy access to the other OS listed here. I can offer a "blind" untested patch, but I'm not really in a position to test the behaviour. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
To the best of my knowledge its not true, because value of Blind is good enough; better than feature disparity IMO. |
||
#[cfg(not(target_vendor = "apple"))] | ||
const SO_NOSIGPIPE: c_int = 0; | ||
|
||
pub struct Socket(FileDesc); | ||
|
||
pub fn init() {} | ||
|
@@ -81,7 +89,11 @@ impl Socket { | |
let fd = cvt(libc::socket(fam, ty, 0))?; | ||
let fd = FileDesc::new(fd); | ||
fd.set_cloexec()?; | ||
Ok(Socket(fd)) | ||
let socket = Socket(fd); | ||
if cfg!(target_vendor = "apple") { | ||
setsockopt(&socket, libc::SOL_SOCKET, SO_NOSIGPIPE, 1)?; | ||
} | ||
Ok(socket) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSG_NOSIGNAL = 0x400
;MSG_NOSIGNAL = 0x20000
;MSG_NOSIGNAL = 0x4000
;MSG_NOSIGNAL = 0x0800
;Would be nice if those were included as well.