listen: Make one of the closure into a function
This make it a bit easier to debug any problems with it.
This commit is contained in:
parent
907008df66
commit
f61df0da1b
|
@ -236,6 +236,18 @@ impl FileDescriptor {
|
|||
.collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
fn from_fd_offset(fd_offset: usize) -> Result<Self, DupError> {
|
||||
SD_LISTEN_FDS_START
|
||||
.checked_add(fd_offset as RawFd)
|
||||
.map(|fd| {
|
||||
// SAFETY: The file descriptor won't be closed by the time we duplicate it.
|
||||
let fd = unsafe { BorrowedFd::borrow_raw(fd) };
|
||||
rustix::fs::fcntl_dupfd_cloexec(fd, 0).map_err(DupError::from)
|
||||
})
|
||||
.expect("Already checked against overflow.")
|
||||
.map(Self::from_fd)
|
||||
}
|
||||
|
||||
fn from_fds(
|
||||
num_fds: usize,
|
||||
) -> Result<impl IntoIterator<Item = Result<Self, DupError>>, GetFdsError> {
|
||||
|
@ -243,17 +255,7 @@ impl FileDescriptor {
|
|||
return Err(GetFdsError::TooManyFDs(num_fds));
|
||||
}
|
||||
|
||||
let ret = (0..num_fds).map(|fd_offset| {
|
||||
SD_LISTEN_FDS_START
|
||||
.checked_add(fd_offset as RawFd)
|
||||
.map(|fd| {
|
||||
// SAFETY: The file descriptor won't be closed by the time we duplicate it.
|
||||
let fd = unsafe { BorrowedFd::borrow_raw(fd) };
|
||||
rustix::fs::fcntl_dupfd_cloexec(fd, 0).map_err(DupError::from)
|
||||
})
|
||||
.expect("Already checked against overflow.")
|
||||
.map(Self::from_fd)
|
||||
});
|
||||
let ret = (0..num_fds).map(Self::from_fd_offset);
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue