Show More
@@ -5,7 +5,7 b'' | |||||
5 |
|
5 | |||
6 | //! Low-level utility for signal and process handling. |
|
6 | //! Low-level utility for signal and process handling. | |
7 |
|
7 | |||
8 | use libc::{c_int, size_t, ssize_t}; |
|
8 | use libc::{self, c_int, size_t, ssize_t}; | |
9 | use std::io; |
|
9 | use std::io; | |
10 | use std::os::unix::io::RawFd; |
|
10 | use std::os::unix::io::RawFd; | |
11 |
|
11 | |||
@@ -15,6 +15,19 b' extern "C" {' | |||||
15 | fn sendfds(sockfd: c_int, fds: *const c_int, fdlen: size_t) -> ssize_t; |
|
15 | fn sendfds(sockfd: c_int, fds: *const c_int, fdlen: size_t) -> ssize_t; | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
|
18 | /// Changes the given fd to blocking mode. | |||
|
19 | pub fn set_blocking_fd(fd: RawFd) -> io::Result<()> { | |||
|
20 | let flags = unsafe { libc::fcntl(fd, libc::F_GETFL) }; | |||
|
21 | if flags < 0 { | |||
|
22 | return Err(io::Error::last_os_error()); | |||
|
23 | } | |||
|
24 | let r = unsafe { libc::fcntl(fd, libc::F_SETFL, flags & !libc::O_NONBLOCK) }; | |||
|
25 | if r < 0 { | |||
|
26 | return Err(io::Error::last_os_error()) | |||
|
27 | } | |||
|
28 | Ok(()) | |||
|
29 | } | |||
|
30 | ||||
18 | /// Sends file descriptors via the given socket. |
|
31 | /// Sends file descriptors via the given socket. | |
19 | pub fn send_raw_fds(sock_fd: RawFd, fds: &[RawFd]) -> io::Result<()> { |
|
32 | pub fn send_raw_fds(sock_fd: RawFd, fds: &[RawFd]) -> io::Result<()> { | |
20 | let r = unsafe { sendfds(sock_fd, fds.as_ptr(), fds.len() as size_t) }; |
|
33 | let r = unsafe { sendfds(sock_fd, fds.as_ptr(), fds.len() as size_t) }; |
General Comments 0
You need to be logged in to leave comments.
Login now