├── .gitignore
├── .gitmodules
├── .idea
├── .gitignore
├── codeStyleSettings.xml
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── compiler.xml
├── copyright
│ ├── file-descriptors.xml
│ └── profiles_settings.xml
├── dictionaries
│ └── raph.xml
├── encodings.xml
├── inspectionProfiles
│ ├── Project_Default.xml
│ └── profiles_settings.xml
├── libraries
│ └── .gitignore
├── markdown-navigator.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations
│ ├── build_musl.xml
│ ├── check_musl.xml
│ └── clean.xml
└── vcs.xml
├── .tm_properties
├── COPYRIGHT
├── Cargo.toml
├── LICENSE
├── README.md
├── clippy.toml
├── file-descriptors.iml
├── rustfmt.toml
└── src
├── AsRawFdExt.rs
├── CreationError.rs
├── InvalidPathReason.rs
├── RawFdExt.rs
├── SpecialFileOpenError.rs
├── StructReadError.rs
├── StructWriteError.rs
├── VectoredRead.rs
├── VectoredWrite.rs
├── character_device
├── CharacterDeviceFileDescriptor.rs
└── mod.rs
├── epoll
├── EPollAddError.rs
├── EPollAddFlags.rs
├── EPollEventFlags.rs
├── EPollFileDescriptor.rs
├── EPollInformationItem.rs
├── EPollModifyError.rs
├── EPollModifyFlags.rs
├── EPollTimeOut.rs
├── EPollWaitError.rs
├── mod.rs
└── syscall
│ ├── EPOLL.rs
│ ├── epoll_create1.rs
│ ├── epoll_ctl.rs
│ ├── epoll_data_t.rs
│ ├── epoll_event.rs
│ ├── epoll_pwait.rs
│ ├── epoll_wait.rs
│ └── mod.rs
├── eventfd
├── EventFileDescriptor.rs
├── mod.rs
└── syscall
│ ├── eventfd.rs
│ ├── eventfd_t.rs
│ └── mod.rs
├── fanotify
├── EventFlags.rs
├── FanotifyFileDescriptor.rs
├── FanotifyMarkError.rs
├── FanotifyReadOrWrite.rs
├── FileStatusFlags.rs
├── MarkEventFlags.rs
├── MarkFlags.rs
├── MarkPath.rs
├── mod.rs
└── syscall
│ ├── fanotify_event_metadata.rs
│ ├── fanotify_init.rs
│ ├── fanotify_mark.rs
│ ├── fanotify_response.rs
│ └── mod.rs
├── file_descriptor_information
├── ExtendFromSlice.rs
├── FileDescriptorInformationHeader.rs
├── extract_fixed_width_value_from_slice.rs
├── extract_space_terminated_value_from_slice.rs
├── invalid_data.rs
└── mod.rs
├── inotify
├── InotifyAddError.rs
├── InotifyAddWatchFlags.rs
├── InotifyEventFlags.rs
├── InotifyFileDescriptor.rs
├── InotifyWatchDescriptor.rs
├── mod.rs
└── syscall
│ ├── inotify_add_watch.rs
│ ├── inotify_event.rs
│ ├── inotify_init1.rs
│ ├── inotify_rm_watch.rs
│ └── mod.rs
├── lib.rs
├── path_bytes_without_trailing_nul.rs
├── pipes_and_fifos
├── PipeFileDescriptor.rs
├── ReceivePipeFileDescriptor.rs
├── SendPipeFileDescriptor.rs
├── SpliceRecipient.rs
├── SpliceSender.rs
├── mod.rs
└── syscall
│ ├── SPLICE_F.rs
│ ├── mod.rs
│ ├── open.rs
│ ├── pipe2.rs
│ ├── splice.rs
│ ├── tee.rs
│ └── vmsplice.rs
├── posix_message_queues
├── OpenOrCreatePosixMessageQueue.rs
├── OptionalPosixMessageQueueCreateSettings.rs
├── PosixMessagePriority.rs
├── PosixMessageQueue.rs
├── PosixMessageQueueConstraints.rs
├── PosixMessageQueueCreateSendOrReceive.rs
├── PosixMessageQueueCreateSettings.rs
├── PosixMessageQueueFileDescriptor.rs
├── PosixMessageQueueUnlinkError.rs
├── Receive.rs
├── ReceivePosixMessageQueueFileDescriptor.rs
├── Send.rs
├── SendAndReceivePosixMessageQueueFileDescriptor.rs
├── SendPosixMessageQueueFileDescriptor.rs
├── mod.rs
└── syscall
│ ├── mod.rs
│ ├── mq_attr.rs
│ ├── mq_getattr.rs
│ ├── mq_open.rs
│ ├── mq_timedreceive.rs
│ ├── mq_timedsend.rs
│ ├── mq_unlink.rs
│ └── mqd_t.rs
├── sendfile
├── SendFile.rs
└── mod.rs
├── signalfd
├── ArithmeticErrorCode.rs
├── BusCode.rs
├── BusFaultData.rs
├── ChildCode.rs
├── ChildData.rs
├── Code.rs
├── EmulatorTrapCode.rs
├── FaultData.rs
├── GenericSignalData.rs
├── IllegalInstructionCode.rs
├── PollCode.rs
├── PollData.rs
├── SegmentationFaultCode.rs
├── SignalFileDescriptor.rs
├── SignalHandler.rs
├── SpecificSignalData.rs
├── SystemCallCode.rs
├── SystemCallData.rs
├── TrapCode.rs
├── UserspaceSignalCode.rs
├── mod.rs
└── syscall
│ ├── SIGRT.rs
│ ├── SI_.rs
│ ├── mod.rs
│ ├── signalfd.rs
│ └── signalfd_siginfo.rs
├── socket
├── AcceptedConnection.rs
├── AcceptedConnectionEnum.rs
├── ConnectionFailedReason.rs
├── Credentials.rs
├── DatagramClientSocketFileDescriptor.rs
├── DatagramClientSocketFileDescriptorEnum.rs
├── DatagramClientSocketInternetProtocolVersion4FileDescriptor.rs
├── DatagramClientSocketInternetProtocolVersion6FileDescriptor.rs
├── DatagramClientSocketUnixDomainFileDescriptor.rs
├── DatagramServerListenerSocketFileDescriptor.rs
├── DatagramServerListenerSocketFileDescriptorEnum.rs
├── DatagramServerListenerSocketInternetProtocolVersion4FileDescriptor.rs
├── DatagramServerListenerSocketInternetProtocolVersion6FileDescriptor.rs
├── DatagramServerListenerSocketUnixDomainFileDescriptor.rs
├── ErrorFlags.rs
├── FilePathInvalidReason.rs
├── InfinibandSocketAddress.rs
├── MessageHeadersIterator.rs
├── NewSocketClientError.rs
├── NewSocketServerListenerError.rs
├── ReceiveFileDescriptorsError.rs
├── ReceiveFlags.rs
├── ReceivedMessageHelper.rs
├── ReceivedMessages.rs
├── SendFlags.rs
├── SocketAcceptError.rs
├── SocketAddress.rs
├── SocketBindError.rs
├── SocketConnectError.rs
├── SocketData.rs
├── SocketFileDescriptor.rs
├── SocketListenError.rs
├── StreamingServerListenerSocketFileDescriptor.rs
├── StreamingServerListenerSocketFileDescriptorEnum.rs
├── StreamingServerListenerSocketInternetProtocolVersion4FileDescriptor.rs
├── StreamingServerListenerSocketInternetProtocolVersion6FileDescriptor.rs
├── StreamingServerListenerSocketUnixDomainFileDescriptor.rs
├── StreamingSocketFileDescriptor.rs
├── StreamingSocketFileDescriptorEnum.rs
├── StreamingSocketInternetProtocolVersion4FileDescriptor.rs
├── StreamingSocketInternetProtocolVersion6FileDescriptor.rs
├── StreamingSocketUnixDomainFileDescriptor.rs
├── UnixSocketAddress.rs
├── mod.rs
└── syscall
│ ├── MSG_.rs
│ ├── SCM_.rs
│ ├── SOL_.rs
│ ├── SO_.rs
│ ├── TCP_.rs
│ ├── accept4.rs
│ ├── bind.rs
│ ├── cmsghdr.rs
│ ├── connect.rs
│ ├── getsockname.rs
│ ├── getsockopt.rs
│ ├── ib_addr.rs
│ ├── in6_addr.rs
│ ├── in_addr.rs
│ ├── listen.rs
│ ├── mmsghdr.rs
│ ├── mod.rs
│ ├── msghdr.rs
│ ├── recvfrom.rs
│ ├── recvmmsg.rs
│ ├── recvmsg.rs
│ ├── sendmsg.rs
│ ├── sendto.rs
│ ├── setsockopt.rs
│ ├── shutdown.rs
│ ├── sockaddr_ib.rs
│ ├── sockaddr_in.rs
│ ├── sockaddr_in6.rs
│ ├── sockaddr_storage.rs
│ ├── sockaddr_un.rs
│ ├── socket.rs
│ ├── socketpair.rs
│ └── ucred.rs
├── terminal
├── BackspaceDelay.rs
├── BaudRate.rs
├── BitsPerByte.rs
├── CanonicalEchoKillCharacter.rs
├── CanonicalSettings.rs
├── CarriageReturnDelay.rs
├── Character.rs
├── CharacterSettings.rs
├── ControlModeFlagSettings.rs
├── CurrentTerminalSettings.rs
├── Echo.rs
├── FlagSetting.rs
├── FormFeedDelay.rs
├── HorizontalTabDelay.rs
├── InputModeFlag.rs
├── InputModeFlagSettings.rs
├── LocalModeFlagSettings.rs
├── MiscellaneousControlModeFlag.rs
├── MiscellaneousControlModeFlagSettings.rs
├── MiscellaneousLocalModeFlag.rs
├── MiscellaneousLocalModeFlagSettings.rs
├── MiscellaneousOutputModeFlag.rs
├── MiscellaneousOutputModeFlagSettings.rs
├── MultipleBits.rs
├── NewLineDelay.rs
├── OutputModeFlagSettings.rs
├── Parity.rs
├── SignalRaising.rs
├── StopBits.rs
├── TerminalFileDescriptor.rs
├── TerminalMode.rs
├── TerminalSettings.rs
├── TerminalSettingsError.rs
├── VerticalTabDelay.rs
├── WhenToChangeTerminalAttributes.rs
├── c
│ ├── B.rs
│ ├── C.rs
│ ├── EXT.rs
│ ├── I.rs
│ ├── L.rs
│ ├── NCCS.rs
│ ├── O.rs
│ ├── TCSA.rs
│ ├── V.rs
│ ├── _POSIX_VDISABLE.rs
│ ├── cc_t.rs
│ ├── cfgetispeed.rs
│ ├── cfgetospeed.rs
│ ├── cfmakeraw.rs
│ ├── cfsetispeed.rs
│ ├── cfsetospeed.rs
│ ├── cfsetspeed.rs
│ ├── mod.rs
│ ├── speed_t.rs
│ ├── tcdrain.rs
│ ├── tcflag_t.rs
│ ├── tcflow.rs
│ ├── tcflush.rs
│ ├── tcgetattr.rs
│ ├── tcgetsid.rs
│ ├── tcsendbreak.rs
│ ├── tcsetattr.rs
│ └── termios.rs
└── mod.rs
└── timerfd
├── TimerClock.rs
├── TimerFileDescriptor.rs
├── TimerSetChoices.rs
├── mod.rs
└── syscall
├── itimerspec.rs
├── mod.rs
├── timerfd_create.rs
├── timerfd_gettime.rs
└── timerfd_settime.rs
/.gitignore:
--------------------------------------------------------------------------------
1 | .cargo/.gitignore
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule ".cargo"]
2 | path = .cargo
3 | url = https://github.com/lemonrock/.cargo.git
4 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | workspace.xml
2 |
--------------------------------------------------------------------------------
/.idea/codeStyleSettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/file-descriptors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/libraries/.gitignore:
--------------------------------------------------------------------------------
1 | *.xml
2 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/runConfigurations/build_musl.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/runConfigurations/check_musl.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/runConfigurations/clean.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.tm_properties:
--------------------------------------------------------------------------------
1 | .cargo/.tm_properties
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | # This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | # Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | [package]
6 | name = "file-descriptors"
7 | description = "Wrapper around the common kinds of (mostly Linux) file descriptors, including sockets, pipes, FIFOs, terminals, serial ports, character devices, epoll, POSIX message queues, timerfd, eventfd, signalfd fanotify and inotify"
8 | keywords = ["file-descriptors", "fd", "serial", "terminal", "sockets"]
9 | categories = ["asynchronous", "external-ffi-bindings", "network-programming", "os::unix-apis"]
10 | license = "MIT"
11 | authors = ["Raphael Cohn "]
12 | homepage = "https://github.com/lemonrock/file-descriptors"
13 | repository = "https://github.com/lemonrock/file-descriptors.git"
14 | exclude = ["*"]
15 | include = ["README.md", "LICENSE", "COPYRIGHT", "src/**/*.rs", "Cargo.toml", "rustfmt.toml", "clippy.toml"]
16 | readme = "README.md"
17 | publish = true
18 | version = "0.9.1"
19 |
20 | [dependencies]
21 | cfg-if = "^0.1.6"
22 |
23 | [target.'cfg(unix)'.dependencies]
24 | libc = "^0.2.44"
25 |
26 | [target.'cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuschia", target_os = "linux", target_os = "solaris", target_env = "uclibc"))'.dependencies]
27 | arrayvec = { version = "^0.4.9", features = ["array-sizes-33-128"] }
28 | bitflags = "^1.0"
29 | errno = "^0.2.4"
30 | likely = "^0.1"
31 | memchr = "^2.1.2"
32 | strum = "^0.13.0"
33 | strum_macros = "^0.13.0"
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | LICENSE terms are documented in the COPYRIGHT file at the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
2 |
--------------------------------------------------------------------------------
/clippy.toml:
--------------------------------------------------------------------------------
1 | .cargo/clippy.toml
--------------------------------------------------------------------------------
/file-descriptors.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/rustfmt.toml:
--------------------------------------------------------------------------------
1 | .cargo/rustfmt.toml
--------------------------------------------------------------------------------
/src/AsRawFdExt.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2020 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Extensions for a file descriptor.
6 | pub trait AsRawFdExt: AsRawFd
7 | {
8 | /// Make a file descriptor blocking (all file descriptors in this library are ordinarily non-blocking)
9 | #[inline(always)]
10 | fn make_blocking(&self)
11 | {
12 | let raw_file_descriptor = self.as_raw_fd();
13 |
14 | let result = unsafe { fcntl(raw_file_descriptor, F_GETFL, 0) };
15 | let flags = if likely!(result >= 0)
16 | {
17 | result
18 | }
19 | else if likely!(result == -1)
20 | {
21 | panic!("Error from fcntl F_GETFL with `{}`", errno())
22 | }
23 | else
24 | {
25 | panic!("Unexpected result from fcntl F_GETFL of `{}`", result)
26 | };
27 |
28 | let flags_without_non_block = flags & !O_NONBLOCK;
29 |
30 | let result = unsafe { fcntl(raw_file_descriptor, F_SETFL, flags_without_non_block) };
31 | if likely!(result == 0)
32 | {
33 | ()
34 | }
35 | else if likely!(result == -1)
36 | {
37 | panic!("Error from fcntl F_SETFL with `{}`", errno())
38 | }
39 | else
40 | {
41 | panic!("Unexpected result from fcntl F_SETFL of `{}`", result)
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/InvalidPathReason.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Reason given for why a path is an invalid for a FIFO.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum InvalidPathReason
8 | {
9 | /// Equivalent to `ELOOP`.
10 | TooManySymbolicLinks,
11 |
12 | /// Equivalent to `ENAMETOOLONG`.
13 | TooLong,
14 |
15 | /// Equivalent to `EISDIR`.
16 | IsADirectory,
17 |
18 | /// Does not exist.
19 | ///
20 | /// A component of the FIFO path does not exist.
21 | DoesNotExist,
22 |
23 | /// One of the parent components of the path (ie not the file name) is not a directory.
24 | ParentComponentIsNotADirectory,
25 |
26 | /// The path points to something that exists but:-
27 | ///
28 | /// * it is not a device special file (character or block device) backed by a device, or;
29 | /// * it is on a read-only file system and writes need to occur (this should not normally occur), or;
30 | /// * it is an executable image currently being executed and writes need to occur.
31 | ExistsButCanNotBeUsed,
32 | }
33 |
--------------------------------------------------------------------------------
/src/RawFdExt.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Common raw file descriptor extensions.
6 | pub trait RawFdExt
7 | {
8 | /// Close a file descriptor.
9 | fn close(self);
10 | }
11 |
12 | impl RawFdExt for RawFd
13 | {
14 | #[inline(always)]
15 | fn close(self)
16 | {
17 | // Please see and for why ignoring the `EINTR` error on close is actually sane.
18 | //
19 | // Frankly, the defects here are those of POSIX: (a) signals, and (b) using a file descriptor so small that it isn't thread safe.
20 | //
21 | // To be fair, both signals and file descriptors predate threads by a long way.
22 | unsafe { close(self) };
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/StructReadError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An error that can occur during read.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum StructReadError
8 | {
9 | /// There is no data to read at this time.
10 | WouldBlock,
11 |
12 | /// For timers: the timer was cancelled because it depends on the realtime clock and the realtime clock was adjusted.
13 | ///
14 | /// Not obvious if this can occur for other file descriptors.
15 | Cancelled,
16 |
17 | /// `EINTR` occurred; this can be handled by either re-trying the read operation or might actual be fatal depending on the signal handling strategy in use.
18 | Interrupted,
19 | }
20 |
21 | impl Display for StructReadError
22 | {
23 | #[inline(always)]
24 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
25 | {
26 | ::fmt(self, f)
27 | }
28 | }
29 |
30 | impl error::Error for StructReadError
31 | {
32 | }
33 |
--------------------------------------------------------------------------------
/src/StructWriteError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An error that can occur during read of a timer instance.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum StructWriteError
8 | {
9 | /// It is not possible to write events at this time.
10 | ///
11 | /// This might be because the event counter is currently at its maximum.
12 | WouldBlock,
13 |
14 | /// Event was cancelled; it is not obvious whether this can actually ever occur.
15 | Cancelled,
16 |
17 | /// `EINTR` occurred; this can be handled by either re-trying the write-like operation or might actual be fatal depending on the signal handling strategy in use.
18 | Interrupted,
19 | }
20 |
21 | impl Display for StructWriteError
22 | {
23 | #[inline(always)]
24 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
25 | {
26 | ::fmt(self, f)
27 | }
28 | }
29 |
30 | impl error::Error for StructWriteError
31 | {
32 | }
33 |
--------------------------------------------------------------------------------
/src/character_device/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 | use super::pipes_and_fifos::SpliceRecipient;
7 | use super::pipes_and_fifos::SpliceSender;
8 | use super::pipes_and_fifos::syscall::open;
9 | use ::libc::ENAMETOOLONG;
10 | use ::libc::ENXIO;
11 | use ::libc::EOVERFLOW;
12 | use ::libc::EROFS;
13 | use ::libc::ETXTBSY;
14 | use ::std::ffi::CString;
15 |
16 |
17 | include!("CharacterDeviceFileDescriptor.rs");
18 |
--------------------------------------------------------------------------------
/src/epoll/EPollAddError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Error for adding to an epoll instance.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum EPollAddError
8 | {
9 | /// There was insufficient kernel memory to complete the operation.
10 | ThereWasInsufficientKernelMemory,
11 |
12 | /// The limit imposed by `/proc/sys/fs/epoll/max_user_watches` would be exceeded.
13 | LimitOnWatchesWouldBeExceeded,
14 | }
15 |
16 | impl Display for EPollAddError
17 | {
18 | #[inline(always)]
19 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
20 | {
21 | ::fmt(self, f)
22 | }
23 | }
24 |
25 | impl error::Error for EPollAddError
26 | {
27 | }
28 |
--------------------------------------------------------------------------------
/src/epoll/EPollInformationItem.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// EPoll information item from `/proc`.
6 | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub struct EPollInformationItem
8 | {
9 | /// File descriptor.
10 | pub target_file_descriptor: RawFd,
11 |
12 | /// Combination of event flags registered for this item.
13 | pub event_flags: u32,
14 |
15 | /// Token registered (`epoll_data_t`).
16 | pub token: u64,
17 |
18 | /// ? used for checkpoint-restore (CRIU).
19 | pub position: i64,
20 |
21 | /// ? used for checkpoint-restore (CRIU).
22 | pub inode: isize,
23 |
24 | /// ? used for checkpoint-restore (CRIU).
25 | pub sdevice: u32,
26 | }
27 |
--------------------------------------------------------------------------------
/src/epoll/EPollModifyError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Error for modifying an epoll instance.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum EPollModifyError
8 | {
9 | /// There was insufficient kernel memory to complete the operation.
10 | ThereWasInsufficientKernelMemory,
11 | }
12 |
13 | impl Display for EPollModifyError
14 | {
15 | #[inline(always)]
16 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
17 | {
18 | ::fmt(self, f)
19 | }
20 | }
21 |
22 | impl error::Error for EPollModifyError
23 | {
24 | }
25 |
--------------------------------------------------------------------------------
/src/epoll/EPollTimeOut.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A time out for an EPoll wait.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub struct EPollTimeOut(i32);
8 |
9 | impl From for EPollTimeOut
10 | {
11 | #[inline(always)]
12 | fn from(value: u16) -> Self
13 | {
14 | EPollTimeOut(value as i32)
15 | }
16 | }
17 |
18 | impl Into for EPollTimeOut
19 | {
20 | #[inline(always)]
21 | fn into(self) -> i32
22 | {
23 | self.0
24 | }
25 | }
26 |
27 | impl EPollTimeOut
28 | {
29 | /// Never times out.
30 | pub const Infinite: Self = EPollTimeOut(-1);
31 |
32 | /// Always times outs.
33 | pub const Immediately: Self = EPollTimeOut(0);
34 |
35 | /// Times out in `n` milliseconds.
36 | #[inline(always)]
37 | pub const fn in_n_milliseconds(n_milliseconds: u16) -> Self
38 | {
39 | EPollTimeOut(n_milliseconds as i32)
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/epoll/EPollWaitError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Error for waiting from an epoll instance.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum EPollWaitError
8 | {
9 | /// Interrupted by a signal.
10 | Interrupted,
11 | }
12 |
13 | impl Display for EPollWaitError
14 | {
15 | #[inline(always)]
16 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
17 | {
18 | ::fmt(self, f)
19 | }
20 | }
21 |
22 | impl error::Error for EPollWaitError
23 | {
24 | }
25 |
--------------------------------------------------------------------------------
/src/epoll/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 | use super::file_descriptor_information::*;
7 | use self::syscall::*;
8 |
9 |
10 | /// System call and libc wrapping of system call specific details.
11 | pub mod syscall;
12 |
13 |
14 | include!("EPollAddError.rs");
15 | include!("EPollAddFlags.rs");
16 | include!("EPollEventFlags.rs");
17 | include!("EPollFileDescriptor.rs");
18 | include!("EPollInformationItem.rs");
19 | include!("EPollModifyError.rs");
20 | include!("EPollModifyFlags.rs");
21 | include!("EPollTimeOut.rs");
22 | include!("EPollWaitError.rs");
23 |
--------------------------------------------------------------------------------
/src/epoll/syscall/epoll_create1.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// This is a flag value to pass to `epoll_create1()`.
6 | ///
7 | /// Sets the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor.
8 | ///
9 | /// Valid on Linux.
10 | /// Valid on Solaris.
11 | pub(crate) const EPOLL_CLOEXEC: c_int = O_CLOEXEC;
12 |
13 | #[link(name = "c")]
14 | extern "C"
15 | {
16 | /// Modern version of epoll suitable for all modern versions of Linux.
17 | ///
18 | /// Flags can be either `0` or `EPOLL_CLOEXEC`.
19 | ///
20 | /// On success, these system calls return a nonnegative file descriptor.
21 | // On error, -1 is returned, and `errno` is set to indicate the error.
22 | ///
23 | /// Errors documented to be returned from `epoll_ctl()` in `errno`:-
24 | ///
25 | /// * `EINVAL`: Invalid value specified in flags.
26 | /// * `EMFILE`: The per-user limit on the number of epoll instances imposed by `/proc/sys/fs/epoll/max_user_instances` was encountered.
27 | /// * `EMFILE`: The per-process limit on the number of open file descriptors has been reached.
28 | /// * `ENFILE`: The system-wide limit on the total number of open files has been reached.
29 | /// * `ENOMEM`: There was insufficient memory to create the kernel object.
30 | pub(crate) fn epoll_create1(flags: c_int) -> c_int;
31 | }
32 |
--------------------------------------------------------------------------------
/src/epoll/syscall/epoll_event.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents an event that occurs after waiting on an epoll file descriptor.
6 | #[derive(Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
7 | #[cfg_attr(target_arch = "x86_64", repr(C, packed))]
8 | #[cfg_attr(not(target_arch = "x86_64"), repr(C))]
9 | pub struct epoll_event
10 | {
11 | /// The events member is a bit mask composed by ORing together zero or more of the following available event types (`EPOLL*` constants).
12 | pub(crate) events: u32,
13 |
14 | /// An union containing the data associated when epoll_ctl was called.
15 | pub(crate) data: epoll_data_t,
16 | }
17 |
18 | impl epoll_event
19 | {
20 | /// Returns readiness flags.
21 | #[inline(always)]
22 | pub fn flags(&self) -> EPollEventFlags
23 | {
24 | unsafe { transmute(self.events) }
25 | }
26 |
27 | /// Token.
28 | #[inline(always)]
29 | pub fn token(&self) -> u64
30 | {
31 | unsafe { self.data.u64 }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/epoll/syscall/epoll_pwait.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// Like `epoll()`, but takes a `sigmask` to atomically change the current pthread's signal mask for the duration of the call to `epoll_wait()`.
9 | pub(crate) fn epoll_pwait(epfd: RawFd, events: *mut epoll_event, maxevents: c_int, timeout: c_int, sigmask: *const sigset_t) -> c_int;
10 | }
11 |
--------------------------------------------------------------------------------
/src/epoll/syscall/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 |
7 |
8 | include!("EPOLL.rs");
9 | include!("epoll_create1.rs");
10 | include!("epoll_ctl.rs");
11 | include!("epoll_data_t.rs");
12 | include!("epoll_event.rs");
13 | include!("epoll_pwait.rs");
14 | include!("epoll_wait.rs");
15 |
--------------------------------------------------------------------------------
/src/eventfd/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 | use self::syscall::*;
7 |
8 |
9 | mod syscall;
10 |
11 |
12 | include!("EventFileDescriptor.rs");
13 |
--------------------------------------------------------------------------------
/src/eventfd/syscall/eventfd.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// `flags` is either zero or a bitwise or of `EFD_CLOEXEC`, `EFD_NONBLOCK` or `EFD_SEMAPHORE`.
9 | ///
10 | /// As its return value, `eventfd()` returns a new file descriptor that can be used to refer to the eventfd object.
11 | /// On error, -1 is returned and errno is set to indicate the error.
12 | ///
13 | /// Documented errors are:-
14 | ///
15 | /// * `EINVAL`: An unsupported value was specified in `flags`.
16 | /// * `EMFILE`: The per-process limit on the number of open file descriptors has been reached.
17 | /// * `ENFILE`: The system-wide limit on the total number of open files has been reached.
18 | /// * `ENODEV`: Could not mount (internal) anonymous inode device.
19 | /// * `ENOMEM`: There was insufficient kernel memory to create the event data structures.
20 | pub(crate) fn eventfd(initval: eventfd_t, flags: c_int) -> c_int;
21 | }
22 |
23 | /// Provide semaphore-like semantics for reads from the new file descriptor.
24 | ///
25 | /// Since Linux 2.6.30.
26 | pub(crate) const EFD_SEMAPHORE: c_int = 1;
27 |
28 | /// Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor.
29 | ///
30 | /// Since Linux 2.6.27.
31 | pub(crate) const EFD_CLOEXEC: c_int = O_CLOEXEC;
32 |
33 | /// Set the `O_NONBLOCK` file status flag on the new file descriptor.
34 | ///
35 | /// Since Linux 2.6.27.
36 | pub(crate) const EFD_NONBLOCK: c_int = O_NONBLOCK;
37 |
--------------------------------------------------------------------------------
/src/eventfd/syscall/eventfd_t.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | pub(crate) type eventfd_t = uint64_t;
6 |
--------------------------------------------------------------------------------
/src/eventfd/syscall/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 |
7 |
8 | include!("eventfd.rs");
9 | include!("eventfd_t.rs");
10 |
--------------------------------------------------------------------------------
/src/fanotify/FanotifyMarkError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An error that can occur during binding of a socket instance.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum FanotifyMarkError
8 | {
9 | /// Kernel would be out of memory.
10 | KernelWouldBeOutOfMemory,
11 |
12 | /// `flags` contained `OnlyDirectory`, and `dirfd` and `path` do not specify a directory, or, the filesystem object indicated by `dirfd` and `pathname` does not exist, or, one was trying to remove a mark from an object which is not marked.
13 | FilePathInvalid,
14 | }
15 |
16 | impl Display for FanotifyMarkError
17 | {
18 | #[inline(always)]
19 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
20 | {
21 | ::fmt(self, f)
22 | }
23 | }
24 |
25 | impl error::Error for FanotifyMarkError
26 | {
27 | }
28 |
--------------------------------------------------------------------------------
/src/fanotify/FanotifyReadOrWrite.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Read, write or read and write?
6 | #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
7 | #[repr(u32)]
8 | pub enum FanotifyReadOrWrite
9 | {
10 | /// Only read.
11 | Read = O_RDONLY as u32 | O_CLOEXEC as u32 | O_NONBLOCK as u32,
12 |
13 | /// Only write.
14 | Write = O_WRONLY as u32 | O_CLOEXEC as u32 | O_NONBLOCK as u32,
15 |
16 | /// Read and write.
17 | ReadAndWrite = O_RDWR as u32 | O_CLOEXEC as u32 | O_NONBLOCK as u32,
18 | }
19 |
--------------------------------------------------------------------------------
/src/fanotify/FileStatusFlags.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | bitflags!
6 | {
7 | /// Flags control the status of a newly opened file descriptor by fanotify.
8 | ///
9 | /// Before Linux 3.18 the features these flags imply was very buggily implemented.
10 | pub struct FileStatusFlags: u32
11 | {
12 | /// Enable support for files exceeding 2 GB.
13 | ///
14 | /// Failing to set this flag will result in an `EOVERFLOW` error when trying to open a large file which is monitored by an fanotify group on a 32-bit system.
15 | ///
16 | /// Note that this value differs widely across architectures, and even is the same as `ReadOnly` on x86-64.
17 | const LargeFile = O_LARGEFILE as u32;
18 |
19 | /// Enable append.
20 | const Append = O_APPEND as u32;
21 |
22 | /// Every `write()` to the file returns only when the contents of the file have been written to disk.
23 | ///
24 | /// This provides the guarantee that when the system call returns the file data is on disk.
25 | const DataSynchronize = O_DSYNC as u32;
26 |
27 | /// Do not adjust access time.
28 | const NoAccessTime = O_NOATIME as u32;
29 |
30 | /// Every `write()` to the file returns only when the contents of the file have been written to disk and also the file metadata has been written to disk.
31 | ///
32 | /// This provides the guarantee that when the system call returns the file data is on disk.
33 | ///
34 | /// It is a stronger guarantee than `DataSynchronize`.
35 | const Synchronize = O_SYNC as u32;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/fanotify/MarkFlags.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | bitflags!
6 | {
7 | /// Flags control the marking of a path.
8 | pub struct MarkFlags: u32
9 | {
10 | /// If pathname is a symbolic link, mark the link itself, rather than the file to which it refers.
11 | ///
12 | /// (By default, `fanotify_mark()` dereferences pathname if it is a symbolic link).
13 | const DoNotFollow = FAN_MARK_DONT_FOLLOW;
14 |
15 | /// If the filesystem object to be marked is not a directory, the error `ENOTDIR` shall be raised.
16 | const OnlyDirectory = FAN_MARK_ONLYDIR;
17 |
18 | /// Mark the mount point specified by pathname.
19 | ///
20 | /// If `pathname` is not itself a mount point, the mount point containing `pathname` will be marked.
21 | /// All directories, subdirectories, and the contained files of the mount point will be monitored.
22 | const Mount = FAN_MARK_MOUNT;
23 |
24 | /// The events in mask shall be added to or removed from the ignore mask.
25 | const IgnoredMask = FAN_MARK_IGNORED_MASK;
26 |
27 | /// The ignore mask shall survive modify events.
28 | ///
29 | /// If this flag is not set, the ignore mask is cleared when a modify event occurs for the ignored file or directory.
30 | const IgnoredSurviveModify = FAN_MARK_IGNORED_SURV_MODIFY;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/fanotify/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 | use self::syscall::*;
7 | use ::libc::AT_FDCWD;
8 | use ::libc::c_uchar;
9 | use ::libc::c_ushort;
10 | use ::libc::c_ulonglong;
11 | use ::libc::c_uint;
12 | use ::libc::O_APPEND;
13 | use ::libc::O_DSYNC;
14 | use ::libc::O_LARGEFILE;
15 | use ::libc::O_NOATIME;
16 | use ::libc::O_SYNC;
17 |
18 |
19 | mod syscall;
20 |
21 |
22 | include!("EventFlags.rs");
23 | include!("FanotifyFileDescriptor.rs");
24 | include!("FanotifyMarkError.rs");
25 | include!("FanotifyReadOrWrite.rs");
26 | include!("FileStatusFlags.rs");
27 | include!("MarkEventFlags.rs");
28 | include!("MarkFlags.rs");
29 | include!("MarkPath.rs");
30 |
--------------------------------------------------------------------------------
/src/fanotify/syscall/fanotify_response.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A response.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | #[repr(C)]
8 | pub struct fanotify_response
9 | {
10 | /// This is the file descriptor from the structure `fanotify_event_metadata`.
11 | fd: RawFd,
12 |
13 | /// This field indicates whether or not the permission is to be granted.
14 | ///
15 | /// Its value must be either `FAN_ALLOW` to allow the file operation or `FAN_DENY` to deny the file operation.
16 | response: c_uint,
17 | }
18 |
19 | impl fanotify_response
20 | {
21 | /// An allow response.
22 | #[inline(always)]
23 | pub const fn allow(fd: RawFd) -> Self
24 | {
25 | Self
26 | {
27 | fd,
28 | response: FAN_ALLOW,
29 | }
30 | }
31 |
32 | /// A deny response.
33 | #[inline(always)]
34 | pub const fn deny(fd: RawFd) -> Self
35 | {
36 | Self
37 | {
38 | fd,
39 | response: FAN_DENY,
40 | }
41 | }
42 | }
43 |
44 | /// Allow grant of permission.
45 | ///
46 | /// Use for field `response` of `fanotify_response`.
47 | pub(crate) const FAN_ALLOW: c_uint = 0x01;
48 |
49 | /// Deny grant of permission.
50 | ///
51 | /// Use for field `response` of `fanotify_response`.
52 | pub(crate) const FAN_DENY: c_uint = 0x02;
53 |
--------------------------------------------------------------------------------
/src/fanotify/syscall/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 |
7 |
8 | include!("fanotify_event_metadata.rs");
9 | include!("fanotify_init.rs");
10 | include!("fanotify_mark.rs");
11 | include!("fanotify_response.rs");
12 |
--------------------------------------------------------------------------------
/src/file_descriptor_information/FileDescriptorInformationHeader.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// EPoll information item from `/proc`.
6 | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub struct FileDescriptorInformationHeader
8 | {
9 | /// File offset (position).
10 | pub file_offset: isize,
11 |
12 | /// Combination of file access mode and file status flags.
13 | pub file_flags: u32,
14 |
15 | /// Mount identifier.
16 | pub mount_identifier: usize,
17 | }
18 |
--------------------------------------------------------------------------------
/src/file_descriptor_information/extract_fixed_width_value_from_slice.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[inline(always)]
6 | pub(crate) fn extract_fixed_width_value_from_slice<'a, Value, Error>(remaining_bytes: &'a [u8], prefix_including_colon_and_whitespace: &'static [u8], width: usize, parser: impl FnOnce(&str) -> Result) -> io::Result<(Value, &'a [u8])>
7 | {
8 | if unlikely!(remaining_bytes.len() < (prefix_including_colon_and_whitespace.len() + width))
9 | {
10 | return Err(invalid_data())
11 | }
12 |
13 | if unlikely!(&remaining_bytes[0 .. prefix_including_colon_and_whitespace.len()] != prefix_including_colon_and_whitespace)
14 | {
15 | return Err(invalid_data())
16 | }
17 |
18 | let raw_value = &remaining_bytes[prefix_including_colon_and_whitespace.len() .. prefix_including_colon_and_whitespace.len() + width];
19 | let raw_value_str = from_utf8(raw_value).map_err(|_utf8_error| invalid_data())?;
20 | let value = parser(raw_value_str).map_err(|_utf8_error| invalid_data())?;
21 |
22 | Ok((value, &remaining_bytes[prefix_including_colon_and_whitespace.len() + width .. ]))
23 | }
24 |
--------------------------------------------------------------------------------
/src/file_descriptor_information/extract_space_terminated_value_from_slice.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[inline(always)]
6 | pub(crate) fn extract_space_terminated_value_from_slice<'a, Value, Error>(remaining_bytes: &'a [u8], prefix_including_colon_and_whitespace: &'static [u8], parser: impl FnOnce(&str) -> Result) -> io::Result<(Value, &'a [u8])>
7 | {
8 | if unlikely!(remaining_bytes.len() < prefix_including_colon_and_whitespace.len())
9 | {
10 | return Err(invalid_data())
11 | }
12 |
13 | if unlikely!(&remaining_bytes[0 .. prefix_including_colon_and_whitespace.len()] != prefix_including_colon_and_whitespace)
14 | {
15 | return Err(invalid_data())
16 | }
17 |
18 | let remaining_bytes = &remaining_bytes[prefix_including_colon_and_whitespace.len() .. ];
19 | let raw_value = match memchr(b' ', remaining_bytes)
20 | {
21 | None => remaining_bytes,
22 |
23 | Some(index) => &remaining_bytes[0 .. index],
24 | };
25 |
26 | let raw_value_str = from_utf8(raw_value).map_err(|_utf8_error| invalid_data())?;
27 | let value = parser(raw_value_str).map_err(|_utf8_error| invalid_data())?;
28 |
29 | Ok((value, &remaining_bytes[raw_value.len() + 1 .. ]))
30 | }
31 |
--------------------------------------------------------------------------------
/src/file_descriptor_information/invalid_data.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[inline(always)]
6 | pub(crate) fn invalid_data() -> io::Error
7 | {
8 | io::Error::from(ErrorKind::InvalidData)
9 | }
10 |
--------------------------------------------------------------------------------
/src/file_descriptor_information/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 |
7 | include!("ExtendFromSlice.rs");
8 | include!("FileDescriptorInformationHeader.rs");
9 | include!("invalid_data.rs");
10 | include!("extract_fixed_width_value_from_slice.rs");
11 | include!("extract_space_terminated_value_from_slice.rs");
12 |
--------------------------------------------------------------------------------
/src/inotify/InotifyAddError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An error that can occur during binding of a socket instance.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum InotifyAddError
8 | {
9 | /// Permission denied.
10 | PermissionDenied,
11 |
12 | /// Kernel would be out of memory.
13 | KernelWouldBeOutOfMemory,
14 |
15 | /// A directory component in `pathname` does not exist or is a dangling symbolic link.
16 | FilePathInvalid,
17 |
18 | /// The limit on the maximum number of watches would be exceeded, or the kernel is lacking a resource required.
19 | ///
20 | /// The maximum number of open (added) watch descriptors is specified in `/proc/sys/fs/inotify/max_user_watches`.
21 | MaximumNumberOfWatchesWouldBeExceeded,
22 | }
23 |
24 | impl Display for InotifyAddError
25 | {
26 | #[inline(always)]
27 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
28 | {
29 | ::fmt(self, f)
30 | }
31 | }
32 |
33 | impl error::Error for InotifyAddError
34 | {
35 | }
36 |
--------------------------------------------------------------------------------
/src/inotify/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 | use self::syscall::*;
7 | use ::std::ffi::CString;
8 | use ::std::rc::Rc;
9 | use ::std::rc::Weak;
10 |
11 |
12 | mod syscall;
13 |
14 |
15 | include!("InotifyAddError.rs");
16 | include!("InotifyAddWatchFlags.rs");
17 | include!("InotifyEventFlags.rs");
18 | include!("InotifyFileDescriptor.rs");
19 | include!("InotifyWatchDescriptor.rs");
20 |
--------------------------------------------------------------------------------
/src/inotify/syscall/inotify_init1.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// `flags` is either zero or a bitwise or of `IN_CLOEXEC` or `IN_NONBLOCK`.
9 | ///
10 | /// As its return value, `inotify_init1()` returns a new file descriptor that can be used to refer to the inotify object.
11 | /// On error, -1 is returned and errno is set to indicate the error.
12 | ///
13 | /// Documented errors are:-
14 | ///
15 | /// * `EINVAL`: An unsupported value was specified in `flags`.
16 | /// * `EMFILE`: The per-process limit on the number of open file descriptors has been reached.
17 | /// * `ENFILE`: The system-wide limit on the total number of open files has been reached.
18 | /// * `ENOMEM`: There was insufficient kernel memory to create the inotify data structures.
19 | ///
20 | /// Since Linux 2.6.27.
21 | pub(crate) fn inotify_init1(flags: c_int) -> c_int;
22 | }
23 |
24 | /// Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor.
25 | ///
26 | /// Since Linux 2.6.27.
27 | pub(crate) const IN_CLOEXEC: c_int = O_CLOEXEC;
28 |
29 | /// Set the `O_NONBLOCK` file status flag on the new file descriptor.
30 | ///
31 | /// Since Linux 2.6.27.
32 | pub(crate) const IN_NONBLOCK: c_int = O_NONBLOCK;
33 |
--------------------------------------------------------------------------------
/src/inotify/syscall/inotify_rm_watch.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// `inotify_rm_watch()` removes the watch associated with the watch descriptor `wd` from the inotify instance associated with the file descriptor `fd`.
9 | ///
10 | /// Removing a watch causes an `IN_IGNORED` event to be generated for this watch descriptor.
11 | ///
12 | /// On success, `inotify_rm_watch()` returns zero.
13 | /// On error `-1` is returned and `errno` is set appropriately.
14 | ///
15 | /// Errors documented to be returned from `inotify_rm_watch()` in `errno`:-
16 | ///
17 | /// * `EBADF`: `fd` is not a valid file descriptor.
18 | /// * `EINVAL`: The watch descriptor `wd` is not valid; or `fd` is not an inotify file descriptor.
19 | ///
20 | /// Since Linux 2.6.13.
21 | pub(crate) fn inotify_rm_watch(fd: RawFd, wd: c_int) -> c_int;
22 | }
23 |
--------------------------------------------------------------------------------
/src/inotify/syscall/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 |
7 |
8 | include!("inotify_add_watch.rs");
9 | include!("inotify_event.rs");
10 | include!("inotify_init1.rs");
11 | include!("inotify_rm_watch.rs");
12 |
--------------------------------------------------------------------------------
/src/path_bytes_without_trailing_nul.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[inline(always)]
6 | pub(crate) fn path_bytes_without_trailing_nul<'a>(path: &'a impl AsRef) -> &'a [u8]
7 | {
8 | path.as_ref().as_os_str().as_bytes()
9 | }
10 |
--------------------------------------------------------------------------------
/src/pipes_and_fifos/PipeFileDescriptor.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2020 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Extensions for a pipe file descriptor to make it useful for clone'd processes.
6 | pub trait PipeFileDescriptor: AsRawFdExt + Sized
7 | {
8 | /// Clones a pipe file descriptor so the pipe is accessible in a child process.
9 | fn clone_for_child_process(&self) -> Self;
10 | }
11 |
--------------------------------------------------------------------------------
/src/pipes_and_fifos/SpliceRecipient.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Marker trait for file descriptors that can receive from `ReceivePipeFileDescriptor::splice_from()`.
6 | ///
7 | /// This includes Rust's `File`.
8 | pub trait SpliceRecipient: AsRawFd
9 | {
10 | }
11 |
12 | impl SpliceRecipient for File
13 | {
14 | }
15 |
--------------------------------------------------------------------------------
/src/pipes_and_fifos/SpliceSender.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Marker trait for file descriptors that can send to `SendPipeFileDescriptor::splice_to()`.
6 | ///
7 | /// This includes Rust's `File`.
8 | pub trait SpliceSender: AsRawFd
9 | {
10 | }
11 |
12 | impl SpliceSender for File
13 | {
14 | }
15 |
--------------------------------------------------------------------------------
/src/pipes_and_fifos/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 | use self::syscall::*;
7 | use ::libc::c_uint;
8 | use ::libc::c_ulong;
9 | use ::libc::ENAMETOOLONG;
10 | use ::libc::ENXIO;
11 | use ::libc::EOVERFLOW;
12 | use ::libc::EROFS;
13 | use ::libc::ESPIPE;
14 | use ::libc::ETXTBSY;
15 | use ::libc::iovec;
16 | use ::std::ffi::CString;
17 | use ::std::mem::transmute_copy;
18 |
19 |
20 | pub(crate) mod syscall;
21 |
22 |
23 | include!("PipeFileDescriptor.rs");
24 | include!("ReceivePipeFileDescriptor.rs");
25 | include!("SendPipeFileDescriptor.rs");
26 | include!("SpliceRecipient.rs");
27 | include!("SpliceSender.rs");
28 |
--------------------------------------------------------------------------------
/src/pipes_and_fifos/syscall/SPLICE_F.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Attempt to move pages instead of copying.
6 | ///
7 | /// This is only a hint to the kernel: pages may still be copied if the kernel cannot move the pages from the pipe, or if the pipe buffers don't refer to full pages.
8 | ///
9 | /// The initial implementation of this flag was buggy: therefore starting in Linux 2.6.21 it is a no-op (but is still permitted in a `splice(`) call); in the future, a correct implementation may be restored.
10 | pub(crate) const SPLICE_F_MOVE: c_uint = 1;
11 |
12 | /// Do not block on I/O.
13 | ///
14 | /// This makes the splice pipe operations nonblocking, but `splice()` may nevertheless block because the file descriptors that are spliced to/from may block (unless they have the `O_NONBLOCK` flag set).
15 | pub(crate) const SPLICE_F_NONBLOCK: c_uint = 2;
16 |
17 | /// More data will be coming in a subsequent splice.
18 | ///
19 | /// This is a helpful hint when the `fd_out` refers to a socket; see also the description of `MSG_MORE` in `man 2 send()`, and the description of `TCP_CORK` in `man 7 tcp`.
20 | pub(crate) const SPLICE_F_MORE: c_uint = 4;
21 |
22 | /// Unused for splice(); see vmsplice(2).
23 | pub(crate) const SPLICE_F_GIFT: c_uint = 8;
24 |
--------------------------------------------------------------------------------
/src/pipes_and_fifos/syscall/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 | use ::libc::loff_t;
7 | use ::libc::ssize_t;
8 |
9 |
10 | include!("open.rs");
11 | include!("pipe2.rs");
12 | include!("splice.rs");
13 | include!("SPLICE_F.rs");
14 | include!("tee.rs");
15 | include!("vmsplice.rs");
16 |
--------------------------------------------------------------------------------
/src/pipes_and_fifos/syscall/pipe2.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// `pipe2()` creates a pipe, a unidirectional data channel that can be used for interprocess communication.
9 | ///
10 | /// The array `pipefd` is used to return two file descriptors referring to the ends of the pipe.
11 | /// `pipefd[0]` refers to the read end of the pipe.
12 | /// `pipefd[1]` refers to the write end of the pipe.
13 | ///
14 | /// Data written to the write end of the pipe is buffered by the kernel until it is read from the read end of the pipe.
15 | ///
16 | /// The following values can be bitwise ORed in flags to obtain different behavior:-
17 | ///
18 | /// * `O_NONBLOCK`: Set the `O_NONBLOCK` file status flag on the two new open file descriptions.
19 | /// * `O_CLOEXEC`: Set the close-on-exec (`FD_CLOEXEC`) flag on the two new file descriptors.
20 | ///
21 | /// On success, zero is returned.
22 | /// On error, `-`1 is returned, and `errno` is set appropriately.
23 | ///
24 | /// The known errors that can be set in `errno` are:-
25 | ///
26 | /// * `EFAULT`: `pipefd` is not valid.
27 | /// * `EINVAL`: Invalid value in `flags`.
28 | /// * `EMFILE`: Too many file descriptors are in use by the process.
29 | /// * `ENFILE`: The system limit on the total number of open files has been reached.
30 | pub(crate) fn pipe2(pipefd: *mut [RawFd; 2], flags: c_int) -> c_int;
31 | }
32 |
--------------------------------------------------------------------------------
/src/pipes_and_fifos/syscall/tee.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | extern "C"
6 | {
7 | /// `tee()` copies data between two file descriptors without copying between kernel address space and user address space.
8 | ///
9 | /// It transfers up to `len` bytes of data from the file descriptor `fd_in` to the file descriptor `fd_out`, where one of the file descriptors must refer to a pipe.
10 | ///
11 | /// The `flags` argument is a bit mask that is composed by ORing together `SPLICE_F_NONBLOCK` and `SPLICE_F_MORE`.
12 | ///
13 | /// Upon successful completion, `tee()` returns the number of bytes copied to or from the pipe.
14 | ///
15 | /// A return value of 0 means end of input.
16 | /// If `fd_in` refers to a pipe, then this means that there was no data to transfer, and it would not make sense to block because there are no writers connected to the write end of the pipe.
17 | ///
18 | /// On error, `tee()` returns `-1` and `errno` is set to indicate the error.
19 | ///
20 | /// The known errors that can be set in `errno` are:-
21 | ///
22 | /// * `EAGAIN`: `SPLICE_F_NONBLOCK` was specified in flags, and the operation would block.
23 | /// * `EINVAL`: `fd_in` and `fd_out` does not refer to a pipe; or `fd_in` and `fd_out` refer to the same pipe.
24 | /// * `ENOMEM`: Out of memory.
25 | pub(crate) fn tee(fd_in: RawFd, fd_out: RawFd, len: size_t, flags: c_uint) -> ssize_t;
26 | }
27 |
--------------------------------------------------------------------------------
/src/pipes_and_fifos/syscall/vmsplice.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | extern "C"
6 | {
7 | /// The `vmsplice()` system call maps `nr_segs` ranges of user memory described by iov into a pipe.
8 | ///
9 | /// The file descriptor `fd` must refer to a pipe.
10 | ///
11 | /// The flags argument is a bit mask that is composed by ORing together any of `SPLICE_F_NONBLOCK` and `SPLICE_F_GIFT`.
12 | ///
13 | /// Upon successful completion, `vmsplice()` returns the number of bytes transferred to the pipe.
14 | /// On error, `vmsplice()` returns `-1` and `errno` is set to indicate the error.
15 | ///
16 | /// The known errors that can be set in `errno` are:-
17 | ///
18 | /// * `EAGAIN`: `SPLICE_F_NONBLOCK` was specified in flags, and the operation would block.
19 | /// * `EBADF`: `fd` is either not valid, or doesn't refer to a pipe.
20 | /// * `EINVAL`: `nr_segs` is greater than `IOV_MAX`; or memory not aligned if `SPLICE_F_GIFT` set.
21 | /// * `ENOMEM`: Out of memory.
22 | pub(crate) fn vmsplice(fd: RawFd, iov: *const iovec, nr_segs: c_ulong, flags: c_uint) -> ssize_t;
23 | }
24 |
--------------------------------------------------------------------------------
/src/posix_message_queues/OptionalPosixMessageQueueCreateSettings.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Optional message queue creation settings.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub struct OptionalPosixMessageQueueCreateSettings
8 | {
9 | /// Must not be zero or negative.
10 | ///
11 | /// Default (if this structure is omitted during creation) is in `/proc/sys/fs/mqueue/msg_default` and is usually `10` since Linux 3.5.
12 | ///
13 | /// The maximum value is in `/proc/sys/fs/mqueue/msg_max`, and is usually `10` since Linux 3.5.
14 | ///
15 | /// Processes with the capability `CAP_SYS_RESOURCE` may exceed this maximum, up to `65,536`.
16 | pub maximum_number_of_enqueued_messages: isize,
17 |
18 | /// Must not be zero or negative.
19 | ///
20 | /// Default () is in `/proc/sys/fs/mqueue/msgsize_default` and is usually `8,192` since Linux 3.5.
21 | ///
22 | /// The maximum value is in `/proc/sys/fs/mqueue/msgsize_max`, and is usually `8,192` since Linux 3.5.
23 | ///
24 | /// Processes with the capability `CAP_SYS_RESOURCE` may exceed this maximum, up to `16,777,216`.
25 | pub maximum_message_size_in_bytes: isize,
26 | }
27 |
--------------------------------------------------------------------------------
/src/posix_message_queues/PosixMessagePriority.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents a message queue priority.
6 | #[derive(Default, Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
7 | pub struct PosixMessagePriority(u16);
8 |
9 | impl Into for PosixMessagePriority
10 | {
11 | #[inline(always)]
12 | fn into(self) -> u16
13 | {
14 | self.0
15 | }
16 | }
17 |
18 | impl Into for PosixMessagePriority
19 | {
20 | #[inline(always)]
21 | fn into(self) -> u32
22 | {
23 | self.0 as u32
24 | }
25 | }
26 |
27 | impl From for PosixMessagePriority
28 | {
29 | #[inline(always)]
30 | fn from(value: u8) -> Self
31 | {
32 | PosixMessagePriority(value as u16)
33 | }
34 | }
35 |
36 | impl TryFrom for PosixMessagePriority
37 | {
38 | type Error = ();
39 |
40 | #[inline(always)]
41 | fn try_from(value: u16) -> Result
42 | {
43 | if value > 32767
44 | {
45 | Err(())
46 | }
47 | else
48 | {
49 | Ok(PosixMessagePriority(value))
50 | }
51 | }
52 | }
53 |
54 | impl TryFrom for PosixMessagePriority
55 | {
56 | type Error = ();
57 |
58 | #[inline(always)]
59 | fn try_from(value: u32) -> Result
60 | {
61 | if value > 32767
62 | {
63 | Err(())
64 | }
65 | else
66 | {
67 | Ok(PosixMessagePriority(value as u16))
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/posix_message_queues/PosixMessageQueueConstraints.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// POSIX message queue constraints.
6 | #[derive(Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub struct PosixMessageQueueConstraints
8 | {
9 | /// Maximum number of enqueued messages.
10 | pub maximum_number_of_enqueued_messages: usize,
11 |
12 | /// Maximum message size in bytes.
13 | pub maximum_message_size_in_bytes: usize,
14 | }
15 |
--------------------------------------------------------------------------------
/src/posix_message_queues/PosixMessageQueueCreateSendOrReceive.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Read, write or read and write?
6 | #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
7 | #[repr(i32)]
8 | pub(crate) enum PosixMessageQueueCreateSendOrReceive
9 | {
10 | /// Only send.
11 | Send = O_WRONLY | O_CLOEXEC | O_NONBLOCK,
12 |
13 | /// Only receive.
14 | Receive = O_RDONLY | O_CLOEXEC | O_NONBLOCK,
15 |
16 | /// Send and receive.
17 | SendAndReceive = O_RDWR | O_CLOEXEC | O_NONBLOCK,
18 | }
19 |
--------------------------------------------------------------------------------
/src/posix_message_queues/PosixMessageQueueCreateSettings.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Settings for creating a queue.
6 | #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
7 | pub struct PosixMessageQueueCreateSettings
8 | {
9 | /// File-like permissions to use.
10 | pub permissions: mode_t,
11 |
12 | /// Optional create settings.
13 | ///
14 | /// If `None`, then Linux applies a default (see documentation of fields on `OptionalPosixMessageQueueCreateSettings`).
15 | pub optional_create_settings: Option,
16 | }
17 |
18 | impl Default for PosixMessageQueueCreateSettings
19 | {
20 | #[inline(always)]
21 | fn default() -> Self
22 | {
23 | Self
24 | {
25 | permissions: S_IRUSR | S_IWUSR,
26 | optional_create_settings: None,
27 | }
28 | }
29 | }
30 |
31 | impl PosixMessageQueueCreateSettings
32 | {
33 | #[inline(always)]
34 | pub(crate) fn invoke_mq_open(&self, name_pointer: *const c_char, oflag: i32) -> c_int
35 | {
36 | let mode = self.permissions;
37 |
38 | match self.optional_create_settings
39 | {
40 | None => unsafe { mq_open(name_pointer, oflag, mode, null_mut::()) },
41 |
42 | Some(ref optional_create_settings) =>
43 | {
44 | let mut attributes = mq_attr::for_create(optional_create_settings);
45 | unsafe { mq_open(name_pointer, oflag, mode, &mut attributes) }
46 | }
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/posix_message_queues/PosixMessageQueueUnlinkError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An error that can occur during binding of a socket instance.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum PosixMessageQueueUnlinkError
8 | {
9 | /// Permission denied.
10 | PermissionDenied,
11 |
12 | /// Does not exist.
13 | DoesNotExist,
14 | }
15 |
16 | impl Display for PosixMessageQueueUnlinkError
17 | {
18 | #[inline(always)]
19 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
20 | {
21 | ::fmt(self, f)
22 | }
23 | }
24 |
25 | impl error::Error for PosixMessageQueueUnlinkError
26 | {
27 | }
28 |
--------------------------------------------------------------------------------
/src/posix_message_queues/Receive.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Receive a message from a queue.
6 | pub trait Receive: PosixMessageQueue
7 | {
8 | /// Returns a tuple of `(message_size, message_priority)`.
9 | ///
10 | /// Fails with a panic if the `message_buffer` is too small for the queue's configured message size (use `PosixMessageQueue::queue_attributes()` to find this).
11 | fn receive(&self, message_buffer: &mut [u8]) -> Result<(usize, PosixMessagePriority), StructReadError>;
12 | }
13 |
--------------------------------------------------------------------------------
/src/posix_message_queues/Send.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Receive a message to a queue.
6 | pub trait Send: PosixMessageQueue
7 | {
8 | /// Sends a message.
9 | ///
10 | /// A message may be empty.
11 | fn send(&self, message_buffer: &[u8], message_priority: PosixMessagePriority) -> Result<(), StructWriteError>;
12 | }
13 |
--------------------------------------------------------------------------------
/src/posix_message_queues/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 | use self::syscall::*;
7 | use ::libc::c_uint;
8 | use ::libc::ENAMETOOLONG;
9 | use ::libc::EEXIST;
10 | use ::libc::EMSGSIZE;
11 | use ::libc::ETIMEDOUT;
12 | use ::libc::mode_t;
13 | use ::libc::O_CREAT;
14 | use ::libc::O_EXCL;
15 | use ::libc::S_IRUSR;
16 | use ::libc::S_IWUSR;
17 | use ::std::convert::TryFrom;
18 |
19 |
20 | mod syscall;
21 |
22 |
23 | include!("PosixMessagePriority.rs");
24 | include!("PosixMessageQueue.rs");
25 | include!("PosixMessageQueueConstraints.rs");
26 | include!("PosixMessageQueueCreateSendOrReceive.rs");
27 | include!("PosixMessageQueueCreateSettings.rs");
28 | include!("PosixMessageQueueFileDescriptor.rs");
29 | include!("PosixMessageQueueUnlinkError.rs");
30 | include!("OpenOrCreatePosixMessageQueue.rs");
31 | include!("OptionalPosixMessageQueueCreateSettings.rs");
32 | include!("Receive.rs");
33 | include!("ReceivePosixMessageQueueFileDescriptor.rs");
34 | include!("Send.rs");
35 | include!("SendAndReceivePosixMessageQueueFileDescriptor.rs");
36 | include!("SendPosixMessageQueueFileDescriptor.rs");
37 |
--------------------------------------------------------------------------------
/src/posix_message_queues/syscall/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 | use ::libc::ssize_t;
7 | use ::libc::timespec;
8 |
9 |
10 | include!("mq_attr.rs");
11 | include!("mqd_t.rs");
12 | include!("mq_getattr.rs");
13 | include!("mq_open.rs");
14 | include!("mq_timedreceive.rs");
15 | include!("mq_timedsend.rs");
16 | include!("mq_unlink.rs");
17 |
--------------------------------------------------------------------------------
/src/posix_message_queues/syscall/mq_getattr.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// Retrieve the attributes of the message queue referred to by the message queue descriptor `mqdes`.
9 | ///
10 | /// On success `mq_getattr()` returns `0`
11 | /// On error, `-1` is returned, with `errno` set to indicate the error.
12 | ///
13 | /// Errors documented to be returned from `mq_getattr()` in `errno`:-
14 | ///
15 | /// * `EBADF`: The message queue descriptor specified in `mqdes` is invalid.
16 | /// * `EINVAL`: `newattr.mq_flags` contained set bits other than `O_NONBLOCK`.
17 | pub(crate) fn mq_getattr(mqdes: mqd_t, attr: *mut mq_attr) -> c_int;
18 | }
19 |
--------------------------------------------------------------------------------
/src/posix_message_queues/syscall/mq_unlink.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// `mq_unlink()` removes the specified message queue name `name`.
9 | ///
10 | /// The message queue name `name` is removed immediately.
11 | /// The queue itself is destroyed once any other processes that have the queue open close their descriptors referring to the queue.
12 | ///
13 | /// Errors documented to be returned from `mq_unlink()` in `errno`:-
14 | ///
15 | /// * `EACCES`: The caller does not have permission to unlink this message queue.
16 | /// * `ENAMETOOLONG`: `name` was too long.
17 | /// * `ENOENT`: There is no message queue with the given `name`.
18 | pub(crate) fn mq_unlink(name: *const c_char) -> c_int;
19 | }
20 |
--------------------------------------------------------------------------------
/src/posix_message_queues/syscall/mqd_t.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | pub(crate) type mqd_t = RawFd;
6 |
--------------------------------------------------------------------------------
/src/sendfile/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 | use ::libc::sendfile;
7 |
8 |
9 | include!("SendFile.rs");
10 |
--------------------------------------------------------------------------------
/src/signalfd/BusFaultData.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Contains fault data relevant to the `SIGBUS` signal.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub struct BusFaultData
8 | {
9 | /// Fault data.
10 | pub fault_data: FaultData,
11 |
12 | /// The least significant bit of the reported address; indicates the extent of the corruption.
13 | ///
14 | /// For example, if a full page was corrupted, this field would be `log2(sysconf(_SC_PAGESIZE))`.
15 | ///
16 | /// Only populated when `code` is `BusCode::HardwareErrorMachineCheckActionRequired` or `BusCode::HardwareErrorMachineCheckActionOptional`.
17 | ///
18 | /// Only populated since Linux 2.6.37, although the codes were added in Linux 2.6.32.
19 | ///
20 | /// When not populated the value is zero.
21 | pub address_least_significant_bit: u16
22 | }
23 |
24 | impl BusFaultData
25 | {
26 | #[inline(always)]
27 | pub(crate) fn new(ssi: &signalfd_siginfo) -> Self
28 | {
29 | Self
30 | {
31 | fault_data: FaultData::new(ssi),
32 | address_least_significant_bit: ssi.ssi_addr_lsb,
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/signalfd/ChildCode.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents a code that can be associated with a kernel-raised `SIGCHLD` signal.
6 | ///
7 | /// Definitions valid as of Linux v4.20-rc5.
8 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9 | #[repr(i32)]
10 | pub enum ChildCode
11 | {
12 | /// Child has exited.
13 | ///
14 | /// Known as `CLD_EXITED` in Linux sources.
15 | Exited = 1,
16 |
17 | /// Child was killed.
18 | ///
19 | /// Known as `CLD_KILLED` in Linux sources.
20 | Killed = 2,
21 |
22 | /// Child terminated abnormally.
23 | ///
24 | /// Known as `CLD_DUMPED` in Linux sources.
25 | TerminatedAbnormally = 3,
26 |
27 | /// Traced child has trapped.
28 | ///
29 | /// Known as `CLD_TRAPPED` in Linux sources.
30 | Trapped = 4,
31 |
32 | /// Child has stopped.
33 | ///
34 | /// 'Stopped' in this case refers to process control.
35 | ///
36 | /// Known as `CLD_STOPPED` in Linux sources.
37 | Stopped = 5,
38 |
39 | /// Child has continued.
40 | ///
41 | /// 'Continued' in this case refers to process control.
42 | ///
43 | /// Known as `CLD_CONTINUED` in Linux sources.
44 | Continued = 6,
45 | }
46 |
47 | impl Into for ChildCode
48 | {
49 | #[inline(always)]
50 | fn into(self) -> i32
51 | {
52 | self as i32
53 | }
54 | }
55 |
56 | impl Code for ChildCode
57 | {
58 | type Data = ChildData;
59 |
60 | const InclusiveMaximum: Self = ChildCode::Continued;
61 |
62 | #[inline(always)]
63 | fn convert(code: i32) -> Self
64 | {
65 | unsafe { transmute(code) }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/signalfd/ChildData.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Contains data relevant to the `SIGCHLD` signal.
6 | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub struct ChildData
8 | {
9 | /// Child process identifier.
10 | pid: pid_t,
11 |
12 | /// Child user identifier.
13 | uid: uid_t,
14 |
15 | /// The child's exit code or exit code with signal code; use `status & 0x7F` to separate.
16 | status: i32,
17 |
18 | /// User CPU time consumed in 'clock ticks'.
19 | ///
20 | /// The number of 'clock ticks' per second can be found by calling `sysconf(_SC_CLK_TCK)`.
21 | /// This is always `100` for the musl libc.
22 | user_cpu_time_consumed_in_clock_ticks: u64,
23 |
24 | /// System CPU time consumed in 'clock ticks'.
25 | ///
26 | /// The number of 'clock ticks' per second can be found by calling `sysconf(_SC_CLK_TCK)`.
27 | /// This is always `100` for the musl libc.
28 | system_cpu_time_consumed_in_clock_ticks: u64,
29 | }
30 |
31 | impl ChildData
32 | {
33 | #[inline(always)]
34 | pub(crate) fn new(ssi: &signalfd_siginfo) -> Self
35 | {
36 | Self
37 | {
38 | pid: ssi.ssi_pid,
39 | uid: ssi.ssi_uid,
40 | status: ssi.ssi_status,
41 | user_cpu_time_consumed_in_clock_ticks: ssi.ssi_utime,
42 | system_cpu_time_consumed_in_clock_ticks: ssi.ssi_stime,
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/signalfd/Code.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents a code for a signal such as `SIGBUS`.
6 | pub trait Code: Into
7 | {
8 | /// Data structure associated with this code.
9 | type Data: Sized;
10 |
11 | #[doc(hidden)]
12 | const InclusiveMaximum: Self;
13 |
14 | #[doc(hidden)]
15 | fn convert(code: i32) -> Self;
16 | }
17 |
--------------------------------------------------------------------------------
/src/signalfd/EmulatorTrapCode.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents a code that can be associated with a kernel-raised `SIGEMT` signal.
6 | ///
7 | /// This signal only occurs for the Alpha, MIPS and SPARC architectures (but Alpha isn't supported by Rust).
8 | ///
9 | /// Definitions valid as of Linux v4.20-rc5.
10 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
11 | #[repr(i32)]
12 | pub enum EmulatorTrapCode
13 | {
14 | /// Tag overflow.
15 | ///
16 | /// Known as `EMT_TAGOVF` in Linux sources.
17 | TagOverflow = 1,
18 | }
19 |
20 | impl Into for EmulatorTrapCode
21 | {
22 | #[inline(always)]
23 | fn into(self) -> i32
24 | {
25 | self as i32
26 | }
27 | }
28 |
29 | impl Code for EmulatorTrapCode
30 | {
31 | type Data = FaultData;
32 |
33 | const InclusiveMaximum: Self = EmulatorTrapCode::TagOverflow;
34 |
35 | #[inline(always)]
36 | fn convert(code: i32) -> Self
37 | {
38 | unsafe { transmute(code) }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/signalfd/FaultData.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Contains fault data relevant to certain signals.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub struct FaultData
8 | {
9 | /// The address of the fault.
10 | pub address: u64,
11 |
12 | /// The trap number of the fault (only supported on the Alpha, MIPS and SPARC architectures; Rust does not support the Alpha architecture).
13 | ///
14 | /// Where not supported the value is zero.
15 | pub trap_number: u32,
16 | }
17 |
18 | impl FaultData
19 | {
20 | #[inline(always)]
21 | pub(crate) fn new(ssi: &signalfd_siginfo) -> Self
22 | {
23 | Self
24 | {
25 | address: ssi.ssi_addr,
26 | trap_number: ssi.ssi_trapno,
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/signalfd/PollCode.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents a code that can be associated with a kernel-raised `SIGIO` (also known as `SIGPOLL`) signal.
6 | ///
7 | /// Definitions valid as of Linux v4.20-rc5.
8 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9 | #[repr(i32)]
10 | pub enum PollCode
11 | {
12 | /// Data input available.
13 | ///
14 | /// Known as `POLL_IN` in Linux sources.
15 | Input = 1,
16 |
17 | /// Data output available.
18 | ///
19 | /// Known as `POLL_OUT` in Linux sources.
20 | Output = 2,
21 |
22 | /// Input message available.
23 | ///
24 | /// Known as `POLL_MSG` in Linux sources.
25 | InputPosixMessage = 3,
26 |
27 | /// Input / Output (IO) error.
28 | ///
29 | /// Known as `POLL_IN` in Linux sources.
30 | IoError = 4,
31 |
32 | /// Priority input available (eg TCP's deprecated out-of-band urgent data).
33 | ///
34 | /// Known as `POLL_PRI` in Linux sources.
35 | PriorityInput = 5,
36 |
37 | /// Device disconnected (Hung Up).
38 | ///
39 | /// Known as `POLL_HUP` in Linux sources.
40 | HungUp = 6,
41 | }
42 |
43 | impl Into for PollCode
44 | {
45 | #[inline(always)]
46 | fn into(self) -> i32
47 | {
48 | self as i32
49 | }
50 | }
51 |
52 | impl Code for PollCode
53 | {
54 | type Data = PollData;
55 |
56 | const InclusiveMaximum: Self = PollCode::HungUp;
57 |
58 | #[inline(always)]
59 | fn convert(code: i32) -> Self
60 | {
61 | unsafe { transmute(code) }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/signalfd/PollData.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Contains data relevant to the `SIGIO` signal (also known as the `SIGPOLL` signal).
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub struct PollData
8 | {
9 | /// Equivalent to the `revents` field in the struct `pollfd` (see `man 2 poll`).
10 | ///
11 | /// Also known as `ssi_band` and `si_band`.
12 | pub revents: u32,
13 |
14 | /// The file descriptor for which the events are appropriate.
15 | pub file_descriptor: RawFd,
16 | }
17 |
18 | impl PollData
19 | {
20 | #[inline(always)]
21 | pub(crate) fn new(ssi: &signalfd_siginfo) -> Self
22 | {
23 | Self
24 | {
25 | revents: ssi.ssi_band,
26 | file_descriptor: ssi.ssi_fd as RawFd,
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/signalfd/SpecificSignalData.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Potentially specific signal data.
6 | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum SpecificSignalData
8 | {
9 | /// Generic signal data.
10 | Generic(GenericSignalData),
11 |
12 | /// For some signals, such as `SIGBUS`, the data will have a code and some valid fields.
13 | ///
14 | /// These signals originate within the kernel and the data is safe to rely upon.
15 | ///
16 | /// The first field is data, the second is a signal code (not the same thing as a signal number).
17 | Specific(C::Data, C),
18 | }
19 |
--------------------------------------------------------------------------------
/src/signalfd/SystemCallCode.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents a code that can be associated with a kernel-raised `SIGSYS` signal.
6 | ///
7 | /// Definitions valid as of Linux v4.20-rc5.
8 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9 | #[repr(i32)]
10 | pub enum SystemCallCode
11 | {
12 | /// `seccomp` triggered.
13 | ///
14 | /// Known as `SYS_SECCOMP` in Linux sources.
15 | SeccompTriggered = 1,
16 | }
17 |
18 | impl Into for SystemCallCode
19 | {
20 | #[inline(always)]
21 | fn into(self) -> i32
22 | {
23 | self as i32
24 | }
25 | }
26 |
27 | impl Code for SystemCallCode
28 | {
29 | type Data = SystemCallData;
30 |
31 | const InclusiveMaximum: Self = SystemCallCode::SeccompTriggered;
32 |
33 | #[inline(always)]
34 | fn convert(code: i32) -> Self
35 | {
36 | unsafe { transmute(code) }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/signalfd/SystemCallData.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Contains data relevant to the `SIGSYS` signal (also known as the `SIGUNKNOWN` signal).
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub struct SystemCallData
8 | {
9 | /// The system call number.
10 | pub system_call_number: i32,
11 |
12 | /// The address of the fault.
13 | pub address: u64,
14 |
15 | /// The system call architecture.
16 | ///
17 | /// Where not supported the value is zero.
18 | pub architecture: u32,
19 | }
20 |
21 | impl SystemCallData
22 | {
23 | #[inline(always)]
24 | pub(crate) fn new(ssi: &signalfd_siginfo) -> Self
25 | {
26 | Self
27 | {
28 | system_call_number: ssi.ssi_syscall,
29 | address: ssi.ssi_call_addr,
30 | architecture: ssi.ssi_arch,
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/signalfd/TrapCode.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents a code that can be associated with a kernel-raised `SIGTRAP` signal.
6 | ///
7 | /// Definitions valid as of Linux v4.20-rc5.
8 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9 | #[repr(i32)]
10 | pub enum TrapCode
11 | {
12 | /// Process breakpoint.
13 | ///
14 | /// Known as `TRAP_BRKPT` in Linux sources.
15 | ProcessBreakpoint = 1,
16 |
17 | /// Process trace trap.
18 | ///
19 | /// Known as `TRAP_TRACE` in Linux sources.
20 | ProcessTraceTrap = 2,
21 |
22 | /// Process has taken branch trap.
23 | ///
24 | /// Known as `TRAP_BRANCH` in Linux sources.
25 | ProcessBranchTrap = 3,
26 |
27 | /// Hardware breakpoint or watchpoint.
28 | ///
29 | /// Known as `TRAP_HWBKPT` in Linux sources.
30 | HardwareBreakpointOrWatchpoint = 4,
31 |
32 | /// Undiagnosed trap.
33 | ///
34 | /// Known as `TRAP_UNK` in Linux sources.
35 | Undiagnosed = 5,
36 | }
37 |
38 | impl Into for TrapCode
39 | {
40 | #[inline(always)]
41 | fn into(self) -> i32
42 | {
43 | self as i32
44 | }
45 | }
46 |
47 | impl Code for TrapCode
48 | {
49 | type Data = FaultData;
50 |
51 | const InclusiveMaximum: Self = TrapCode::Undiagnosed;
52 |
53 | #[inline(always)]
54 | fn convert(code: i32) -> Self
55 | {
56 | unsafe { transmute(code) }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/signalfd/syscall/SIGRT.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// This is the Kernel lower limit of `SIGRTMIN`.
6 | pub const SIGRTMIN_Kernel: c_int = 32;
7 |
8 | /// In theory, this is a libc-specific value, but both modern glibc and musl define it as `35` (in the past, when using an older threading implementation, glibc defined it as `34`).
9 | ///
10 | /// The kernel lower-limit is 32.
11 | pub const SIGRTMIN: c_int = 35;
12 |
13 | /// This value is defined by the kernel.
14 | ///
15 | /// There seems to be a bug in musl that defines this value as `127` for MIPS, but the kernel sources disagree.
16 | #[cfg(any(target_arch = "mips", target_arch = "mips64"))] pub const SIGRTMAX: c_int = 128;
17 | /// This value is defined by the kernel.
18 | ///
19 | /// There seems to be a bug in musl that defines this value as `127` for MIPS, but the kernel sources disagree.
20 | #[cfg(not(any(target_arch = "mips", target_arch = "mips64")))] pub const SIGRTMAX: c_int = 64;
21 |
--------------------------------------------------------------------------------
/src/signalfd/syscall/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 |
7 |
8 | include!("SI_.rs");
9 | include!("signalfd.rs");
10 | include!("signalfd_siginfo.rs");
11 | include!("SIGRT.rs");
12 |
--------------------------------------------------------------------------------
/src/socket/AcceptedConnection.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An accepted connection.
6 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub struct AcceptedConnection
8 | {
9 | /// A streaming socket instance between two peers.
10 | pub streaming_socket_file_descriptor: StreamingSocketFileDescriptor,
11 |
12 | /// Peer (remote) address.
13 | pub peer_address: SD,
14 | }
15 |
--------------------------------------------------------------------------------
/src/socket/AcceptedConnectionEnum.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// One of three possible types.
6 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum AcceptedConnectionEnum
8 | {
9 | /// An Internet Protocol (IP) version 4 accepted connection.
10 | InternetProtocolVersion4(AcceptedConnection),
11 |
12 | /// An Internet Protocol (IP) version 6 accepted connection.
13 | InternetProtocolVersion6(AcceptedConnection),
14 |
15 | /// An Unix Domain connection.
16 | UnixDomain(AcceptedConnection),
17 | }
18 |
--------------------------------------------------------------------------------
/src/socket/ConnectionFailedReason.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Additional information on why a connection failed during accept.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum ConnectionFailedReason
8 | {
9 | /// The connection aborted.
10 | Aborted,
11 |
12 | /// Firewall rules denied permission.
13 | FirewallPermissionDenied,
14 |
15 | /// Connection establishment timed out.
16 | TimedOut,
17 |
18 | /// A protocol error (`EPROTO`) occurred.
19 | Protocol,
20 | }
21 |
--------------------------------------------------------------------------------
/src/socket/Credentials.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents credentials that can be passed to and fro over an Unix Domain Socket.
6 | #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | #[repr(C)]
8 | pub struct Credentials
9 | {
10 | /// Process identifier (`pid`).
11 | pub process_identifier: pid_t,
12 |
13 | /// User identifier (`uid`).
14 | pub user_identifier: uid_t,
15 |
16 | /// Group identifier (`gid`).
17 | pub group_identifier: gid_t
18 | }
19 |
--------------------------------------------------------------------------------
/src/socket/DatagramClientSocketFileDescriptorEnum.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents a datagram client socket instance between two peers.
6 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum DatagramClientSocketFileDescriptorEnum
8 | {
9 | /// An Internet Protocol (IP) version 4 streaming socket.
10 | InternetProtocolVersion4(DatagramClientSocketInternetProtocolVersion4FileDescriptor),
11 |
12 | /// An Internet Protocol (IP) version 6 streaming socket.
13 | InternetProtocolVersion6(DatagramClientSocketInternetProtocolVersion6FileDescriptor),
14 |
15 | /// An Unix Domain streaming socket.
16 | UnixDomain(DatagramClientSocketUnixDomainFileDescriptor),
17 | }
18 |
19 | impl AsRawFd for DatagramClientSocketFileDescriptorEnum
20 | {
21 | #[inline(always)]
22 | fn as_raw_fd(&self) -> RawFd
23 | {
24 | use self::DatagramClientSocketFileDescriptorEnum::*;
25 |
26 | match self
27 | {
28 | &InternetProtocolVersion4(ref datagram_client_socket_file_descriptor) => datagram_client_socket_file_descriptor.as_raw_fd(),
29 | &InternetProtocolVersion6(ref datagram_client_socket_file_descriptor) => datagram_client_socket_file_descriptor.as_raw_fd(),
30 | &UnixDomain(ref datagram_client_socket_file_descriptor) => datagram_client_socket_file_descriptor.as_raw_fd(),
31 | }
32 | }
33 | }
34 |
35 | impl AsRawFdExt for DatagramClientSocketFileDescriptorEnum
36 | {
37 | }
38 |
--------------------------------------------------------------------------------
/src/socket/DatagramClientSocketInternetProtocolVersion4FileDescriptor.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A convenience type.
6 | pub type DatagramClientSocketInternetProtocolVersion4FileDescriptor = DatagramClientSocketFileDescriptor;
7 |
--------------------------------------------------------------------------------
/src/socket/DatagramClientSocketInternetProtocolVersion6FileDescriptor.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A convenience type.
6 | pub type DatagramClientSocketInternetProtocolVersion6FileDescriptor = DatagramClientSocketFileDescriptor;
7 |
--------------------------------------------------------------------------------
/src/socket/DatagramClientSocketUnixDomainFileDescriptor.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A convenience type.
6 | pub type DatagramClientSocketUnixDomainFileDescriptor = DatagramClientSocketFileDescriptor;
7 |
--------------------------------------------------------------------------------
/src/socket/DatagramServerListenerSocketFileDescriptorEnum.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents a datagram server listening socket instance between two peers.
6 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum DatagramServerListenerSocketFileDescriptorEnum
8 | {
9 | /// An Internet Protocol (IP) version 4 streaming socket.
10 | InternetProtocolVersion4(DatagramServerListenerSocketInternetProtocolVersion4FileDescriptor),
11 |
12 | /// An Internet Protocol (IP) version 6 streaming socket.
13 | InternetProtocolVersion6(DatagramServerListenerSocketInternetProtocolVersion6FileDescriptor),
14 |
15 | /// An Unix Domain streaming socket.
16 | UnixDomain(DatagramServerListenerSocketUnixDomainFileDescriptor),
17 | }
18 |
19 | impl AsRawFd for DatagramServerListenerSocketFileDescriptorEnum
20 | {
21 | #[inline(always)]
22 | fn as_raw_fd(&self) -> RawFd
23 | {
24 | use self::DatagramServerListenerSocketFileDescriptorEnum::*;
25 |
26 | match self
27 | {
28 | &InternetProtocolVersion4(ref datagram_client_socket_file_descriptor) => datagram_client_socket_file_descriptor.as_raw_fd(),
29 | &InternetProtocolVersion6(ref datagram_client_socket_file_descriptor) => datagram_client_socket_file_descriptor.as_raw_fd(),
30 | &UnixDomain(ref datagram_client_socket_file_descriptor) => datagram_client_socket_file_descriptor.as_raw_fd(),
31 | }
32 | }
33 | }
34 |
35 | impl AsRawFdExt for DatagramServerListenerSocketFileDescriptorEnum
36 | {
37 | }
--------------------------------------------------------------------------------
/src/socket/DatagramServerListenerSocketInternetProtocolVersion4FileDescriptor.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A convenience type.
6 | pub type DatagramServerListenerSocketInternetProtocolVersion4FileDescriptor = DatagramServerListenerSocketFileDescriptor;
7 |
--------------------------------------------------------------------------------
/src/socket/DatagramServerListenerSocketInternetProtocolVersion6FileDescriptor.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A convenience type.
6 | pub type DatagramServerListenerSocketInternetProtocolVersion6FileDescriptor = DatagramServerListenerSocketFileDescriptor;
7 |
--------------------------------------------------------------------------------
/src/socket/DatagramServerListenerSocketUnixDomainFileDescriptor.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A convenience type.
6 | pub type DatagramServerListenerSocketUnixDomainFileDescriptor = DatagramServerListenerSocketFileDescriptor;
7 |
--------------------------------------------------------------------------------
/src/socket/ErrorFlags.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | bitflags!
6 | {
7 | /// Flags associated with errors when sending or receiving on sockets.
8 | pub struct ErrorFlags: i32
9 | {
10 | /// Is returned to indicate that expedited or out-of-band data were received.
11 | const OutOfBand = MSG_OOB;
12 |
13 | /// Indicates that some control data were discarded due to lack of space in the buffer for ancillary data.
14 | const ControlDataTruncated = MSG_CTRUNC;
15 |
16 | /// Returns the real length of the packet of datagram, even when it was longer than the passed buffer.
17 | const Truncated = MSG_TRUNC;
18 |
19 | /// Indicates end-of-record; the data returned completed a record (generally used with sockets of type `SOCK_SEQPACKET` (eg SCTP)).
20 | ///
21 | /// Used in the `msg_flags` field in the `msghdr` on return of `recvmsg()`.
22 | const EndOfRecord = MSG_EOR;
23 |
24 | /// Indicates that no data was received but an extended error from the socket error queue..
25 | const QueuedErrors = MSG_ERRQUEUE;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/socket/FilePathInvalidReason.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An explanation of the `FilePathInvalid` error that can occur during binding of a socket instance.
6 | #[derive(Debug)]
7 | pub enum FilePathInvalidReason
8 | {
9 | /// In preparing the parent folder, canonicalization of the supplied path failed.
10 | CanonicalizationOfPathFailed(io::Error),
11 |
12 | /// In preparing the parent folder it was discovered that the supplied path does not have a parent folder.
13 | DoesNotHaveAParentFolder,
14 |
15 | /// In preparing the parent folder it was discovered that the supplied path's parent exists and is not a folder.
16 | ParentExistsAndIsNotAFolder,
17 |
18 | /// Setting permissions on an (extant) parent folder failed.
19 | SetParentFolderPermissions(io::Error),
20 |
21 | /// Creating the parent folder failed.
22 | ParentFolderRecursiveCreationFailed(io::Error),
23 |
24 | /// Could not remove a previous file path (either a file or a folder) that represented an Unix Domain Socket.
25 | CouldNotRemovePreviousSocketFilePath(io::Error),
26 |
27 | /// A nonexistent interface was requested or the requested address was not local (eg it was on a NFS mount).
28 | AddressUnavailable,
29 |
30 | /// Too many symbolic links were encountered in resolving the file path.
31 | TooManySymbolicLinksInFilePath,
32 |
33 | /// The file path does not exist.
34 | DoesNotExist,
35 |
36 | /// A component of the file path prefix is not a directory.
37 | FilePathPrefixComponentIsNotADirectory,
38 |
39 | /// The socket inode would reside on a read-only file system.
40 | FilePathIsReadOnly,
41 | }
42 |
--------------------------------------------------------------------------------
/src/socket/InfinibandSocketAddress.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents an infiniband socket address.
6 | #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub struct InfinibandSocketAddress(ib_addr);
8 |
9 | impl InfinibandSocketAddress
10 | {
11 | /// `sib_subnet_prefix` and `sib_interface_id` must be a 64-bit integer in Network Endian form, not Native Endian form.
12 | #[inline(always)]
13 | pub const fn new(sib_subnet_prefix: u64, sib_interface_id: u64) -> Self
14 | {
15 | Self
16 | (
17 | ib_addr
18 | {
19 | sib_subnet_prefix,
20 | sib_interface_id
21 | }
22 | )
23 | }
24 |
25 | /// The 'any' address.
26 | pub const Any: Self = Self(ib_addr::Any);
27 |
28 | /// The 'loopback' address.
29 | pub const Loopback: Self = Self(ib_addr::Loopback);
30 |
31 | /// Is 'any' address.
32 | #[inline(always)]
33 | pub fn is_any(&self) -> bool
34 | {
35 | self.0.is_any()
36 | }
37 |
38 | /// Is 'loopback' address.
39 | #[inline(always)]
40 | pub fn is_loopback(&self) -> bool
41 | {
42 | self.0.is_loopback()
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/socket/MessageHeadersIterator.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[allow(dead_code)]
6 | pub(crate) struct MessageHeadersIterator<'a>
7 | {
8 | parent: &'a msghdr,
9 | next: Option<&'a cmsghdr>,
10 | }
11 |
12 | impl<'a> Iterator for MessageHeadersIterator<'a>
13 | {
14 | type Item = &'a cmsghdr;
15 |
16 | #[inline(always)]
17 | fn next(&mut self) -> Option
18 | {
19 | let next_message_header = self.next.take();
20 | if let Some(next_message_header) = next_message_header
21 | {
22 | self.next = next_message_header.next(self.parent);
23 | }
24 |
25 | next_message_header
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/socket/NewSocketClientError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An error that can occur during creation of a socket listener.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum NewSocketClientError
8 | {
9 | /// Creation.
10 | Creation(CreationError),
11 |
12 | /// Connect.
13 | Connect(SocketConnectError),
14 | }
15 |
16 | impl Display for NewSocketClientError
17 | {
18 | #[inline(always)]
19 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
20 | {
21 | ::fmt(self, f)
22 | }
23 | }
24 |
25 | impl error::Error for NewSocketClientError
26 | {
27 | #[inline(always)]
28 | fn source(&self) -> Option<&(dyn error::Error + 'static)>
29 | {
30 | use self::NewSocketClientError::*;
31 |
32 | match self
33 | {
34 | &Creation(ref error) => Some(error),
35 | &Connect(ref error) => Some(error),
36 | }
37 | }
38 | }
39 |
40 | impl From for NewSocketClientError
41 | {
42 | #[inline(always)]
43 | fn from(error: CreationError) -> Self
44 | {
45 | NewSocketClientError::Creation(error)
46 | }
47 | }
48 |
49 | impl From for NewSocketClientError
50 | {
51 | #[inline(always)]
52 | fn from(error: SocketConnectError) -> Self
53 | {
54 | NewSocketClientError::Connect(error)
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/socket/ReceiveFileDescriptorsError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An error that can occur during receive of file descriptors.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum ReceiveFileDescriptorsError
8 | {
9 | /// A read error that might be possible to handle.
10 | Read(StructReadError),
11 |
12 | /// More than one ancillary message header was received.
13 | MoreThanOneHeader,
14 |
15 | /// A received ancillary message was not for `SOL_SOCKET`.
16 | WasNotSocketLevelPosixMessage,
17 |
18 | /// A received ancillary message was not for `SCM_RIGHTS`.
19 | WasNotScmRights,
20 | }
21 |
22 | impl Display for ReceiveFileDescriptorsError
23 | {
24 | #[inline(always)]
25 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
26 | {
27 | ::fmt(self, f)
28 | }
29 | }
30 |
31 | impl error::Error for ReceiveFileDescriptorsError
32 | {
33 | #[inline(always)]
34 | fn source(&self) -> Option<&(dyn error::Error + 'static)>
35 | {
36 | use self::ReceiveFileDescriptorsError::*;
37 |
38 | match self
39 | {
40 | &Read(ref error) => Some(error),
41 |
42 | &MoreThanOneHeader => None,
43 |
44 | &WasNotSocketLevelPosixMessage => None,
45 |
46 | &WasNotScmRights => None,
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/socket/ReceivedMessageHelper.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | pub(crate) struct ReceivedMessageHelper<'a, SD: SocketData>
6 | {
7 | pub(crate) receive_buffer: &'a mut [u8],
8 | pub(crate) remote_peer_address: SD,
9 | }
10 |
11 | impl<'a, SD: SocketData> ReceivedMessageHelper<'a, SD>
12 | {
13 | #[inline(always)]
14 | pub(crate) fn new(receive_buffer: &'a mut [u8]) -> Self
15 | {
16 | Self
17 | {
18 | receive_buffer,
19 | remote_peer_address: SD::default(),
20 | }
21 | }
22 |
23 | #[inline(always)]
24 | pub(crate) fn new_multi_message_header(&mut self) -> mmsghdr
25 | {
26 | unsafe
27 | {
28 | let c_iovec =
29 | {
30 | // A Rust slice is actually an anonymous struct of `{ pointer_to_array: *mut T, length: usize }`; this is exactly the same layout as a C `iovec`.
31 | let c_iovec: &mut iovec = transmute(&mut self.receive_buffer);
32 | c_iovec
33 | };
34 |
35 | #[allow(deprecated)]
36 | mmsghdr
37 | {
38 | msg_hdr: msghdr::new(&mut self.remote_peer_address as *mut _ as *mut _, size_of::() as u32, c_iovec, 1, null_mut(), 0, uninitialized()),
39 | msg_len: uninitialized(),
40 | }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/socket/SocketAcceptError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An error that can occur during creation of a socket instance.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum SocketAcceptError
8 | {
9 | /// The per-process limit on the number of open file descriptors would be exceeded.
10 | PerProcessLimitOnNumberOfFileDescriptorsWouldBeExceeded,
11 |
12 | /// The system-wide limit on the total number of open files would be exceeded.
13 | SystemWideLimitOnTotalNumberOfFileDescriptorsWouldBeExceeded,
14 |
15 | /// Kernel would be out of memory.
16 | KernelWouldBeOutOfMemory,
17 |
18 | /// Interrupted.
19 | Interrupted,
20 |
21 | /// No more connections to accept for now.
22 | Again,
23 |
24 | /// Connection establishment failed in some way.
25 | ConnectionFailed(ConnectionFailedReason),
26 | }
27 |
28 | impl Display for SocketAcceptError
29 | {
30 | #[inline(always)]
31 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
32 | {
33 | ::fmt(self, f)
34 | }
35 | }
36 |
37 | impl error::Error for SocketAcceptError
38 | {
39 | }
40 |
--------------------------------------------------------------------------------
/src/socket/SocketBindError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An error that can occur during binding of a socket instance.
6 | #[derive(Debug)]
7 | pub enum SocketBindError
8 | {
9 | /// Permission denied.
10 | ///
11 | /// For an Unix Domain Socket, some part of the path not might searchable.
12 | PermissionDenied,
13 |
14 | /// The address is already in use.
15 | AddressInUse,
16 |
17 | /// Kernel would be out of memory.
18 | KernelWouldBeOutOfMemory,
19 |
20 | /// Specifically, for an Unix Domain Socket, additional failures are possible.
21 | FilePathInvalid(FilePathInvalidReason)
22 | }
23 |
24 | impl Display for SocketBindError
25 | {
26 | #[inline(always)]
27 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
28 | {
29 | ::fmt(self, f)
30 | }
31 | }
32 |
33 | impl error::Error for SocketBindError
34 | {
35 | }
36 |
--------------------------------------------------------------------------------
/src/socket/SocketData.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 |
6 | use ::std::convert::AsRef;
7 | use ::std::path::Path;
8 |
9 |
10 | /// Represents socket data.
11 | pub trait SocketData: Sized + Default
12 | {
13 | /// Socket family (eg `AF_UNIX`).
14 | fn family(&self) -> sa_family_t;
15 |
16 | #[doc(hidden)]
17 | #[inline(always)]
18 | fn specialized_drop(socket_file_descriptor: &mut SocketFileDescriptor)
19 | {
20 | socket_file_descriptor.0.close()
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/socket/SocketListenError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An error that can occur during binding of a socket instance.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum SocketListenError
8 | {
9 | /// The address is already in use.
10 | AddressInUse,
11 | }
12 |
13 | impl Display for SocketListenError
14 | {
15 | #[inline(always)]
16 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
17 | {
18 | ::fmt(self, f)
19 | }
20 | }
21 |
22 | impl error::Error for SocketListenError
23 | {
24 | }
25 |
--------------------------------------------------------------------------------
/src/socket/StreamingServerListenerSocketInternetProtocolVersion4FileDescriptor.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A convenience type.
6 | pub type StreamingServerListenerSocketInternetProtocolVersion4FileDescriptor = StreamingServerListenerSocketFileDescriptor;
7 |
--------------------------------------------------------------------------------
/src/socket/StreamingServerListenerSocketInternetProtocolVersion6FileDescriptor.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A convenience type.
6 | pub type StreamingServerListenerSocketInternetProtocolVersion6FileDescriptor = StreamingServerListenerSocketFileDescriptor;
7 |
--------------------------------------------------------------------------------
/src/socket/StreamingServerListenerSocketUnixDomainFileDescriptor.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A convenience type.
6 | pub type StreamingServerListenerSocketUnixDomainFileDescriptor = StreamingServerListenerSocketFileDescriptor;
7 |
--------------------------------------------------------------------------------
/src/socket/StreamingSocketInternetProtocolVersion4FileDescriptor.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A convenience type.
6 | pub type StreamingSocketInternetProtocolVersion4FileDescriptor = StreamingSocketFileDescriptor;
7 |
--------------------------------------------------------------------------------
/src/socket/StreamingSocketInternetProtocolVersion6FileDescriptor.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A convenience type.
6 | pub type StreamingSocketInternetProtocolVersion6FileDescriptor = StreamingSocketFileDescriptor;
7 |
--------------------------------------------------------------------------------
/src/socket/StreamingSocketUnixDomainFileDescriptor.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// A convenience type.
6 | pub type StreamingSocketUnixDomainFileDescriptor = StreamingSocketFileDescriptor;
7 |
--------------------------------------------------------------------------------
/src/socket/UnixSocketAddress.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An Unix socket address.
6 | #[derive(Debug)]
7 | pub enum UnixSocketAddress>
8 | {
9 | /// A file in a file system.
10 | File
11 | {
12 | /// An Unix Domain Socket file path of up to 107 bytes.
13 | socket_file_path: FilePath,
14 |
15 | /// `u32` is the permissions of the parent folder of the file path; it is only used by listeners.
16 | parent_folder_mode: u32,
17 | },
18 |
19 | /// A Linux-specific abstractly named socket.
20 | Abstract
21 | {
22 | /// An abstract name of zero or more bytes.
23 | abstract_name: ArrayVec<[u8; sockaddr_un::PathLength - 1]>,
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/socket/syscall/SCM_.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | pub(crate) const SCM_RIGHTS: c_int = 0x01;
6 |
7 | #[allow(dead_code)]
8 | pub(crate) const SCM_CREDENTIALS: c_int = 0x02;
9 |
10 | #[allow(dead_code)]
11 | pub(crate) const SCM_TIMESTAMP: c_int = SO_TIMESTAMP;
12 |
13 | #[allow(dead_code)]
14 | pub(crate) const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS;
15 |
16 | #[allow(dead_code)]
17 | pub(crate) const SCM_TIMESTAMPING: c_int = SO_TIMESTAMPING;
18 |
19 | #[allow(dead_code)]
20 | pub(crate) const SCM_WIFI_STATUS: c_int = SO_WIFI_STATUS;
21 |
22 | #[allow(dead_code)]
23 | pub(crate) const SCM_TIMESTAMPING_OPT_STATS: c_int = 54;
24 |
25 | #[allow(dead_code)]
26 | pub(crate) const SCM_TIMESTAMPING_PKTINFO: c_int = 58;
27 |
--------------------------------------------------------------------------------
/src/socket/syscall/SOL_.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// MIPS just has to be different.
6 | #[cfg(all(any(target_arch = "android", target_arch = "linux"), any(target_arch = "mips", target_arch = "mips64", target_arch = "sparc64")))] pub(crate) const SOL_SOCKET: c_int = 0xFFFF;
7 | #[cfg(not(all(any(target_arch = "android", target_arch = "linux"), any(target_arch = "mips", target_arch = "mips64", target_arch = "sparc64"))))] pub(crate) const SOL_SOCKET: c_int = 1;
8 |
9 | ///
10 | pub(crate) const SOL_TCP: c_int = 6;
11 |
12 | ///
13 | #[allow(dead_code)]
14 | pub(crate) const SOL_UDP: c_int = 17;
15 |
--------------------------------------------------------------------------------
/src/socket/syscall/getsockname.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// `getsockname()` returns the current address to which the socket `sockfd` is bound, in the buffer pointed to by `addr`.
9 | /// The `addrlen` argument should be initialized to indicate the amount of space (in bytes) pointed to by `addr`.
10 | /// On return it contains the actual size of the socket address.
11 | ///
12 | /// The returned address is truncated if the buffer provided is too small; in this case, addrlen will return a value greater than was supplied to the call.
13 | ///
14 | /// On success, zero is returned.
15 | /// On error, `-1` is returned, and `errno` is set appropriately.
16 | ///
17 | /// The known errors that can be set in `errno` are:-
18 | ///
19 | /// * `EBADF`: The argument `sockfd` is not a valid file descriptor.
20 | /// * `EFAULT`: The `addr` argument points to memory not in a valid part of the process address space.
21 | /// * `EINVAL`: `addrlen` is invalid.
22 | /// * `ENOBUFS`: Insufficient resources were available in the system to perform the operation.
23 | /// * `ENOTSOCK`: The file descriptor `sockfd` does not refer to a socket.
24 | pub(crate) fn getsockname(sockfd: RawFd, addr: *mut sockaddr_storage, addrlen: *mut socklen_t) -> c_int;
25 | }
26 |
--------------------------------------------------------------------------------
/src/socket/syscall/getsockopt.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// See documentation for `setsockopt()` for common documentation.
9 | ///
10 | /// For `getsockopt()`, `optlen` is a value-result argument, initially containing the size of the buffer pointed to by `optval`, and modified on return to indicate the actual size of the value returned.
11 | ///
12 | /// If no option value is to be supplied or returned, `optva`l may be `NULL`.
13 | pub(crate) fn getsockopt(sockfd: RawFd, level: c_int, optname: c_int, optval: *mut c_void, optlen: *mut socklen_t) -> c_int;
14 | }
15 |
--------------------------------------------------------------------------------
/src/socket/syscall/ib_addr.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Infiniband address.
6 | #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | #[repr(C)]
8 | pub struct ib_addr
9 | {
10 | /// Must be a 64-bit integer in Network Endian form, not Native Endian form.
11 | pub sib_subnet_prefix: u64,
12 |
13 | /// Must be a 64-bit integer in Network Endian form, not Native Endian form.
14 | pub sib_interface_id: u64,
15 | }
16 |
17 | impl ib_addr
18 | {
19 | /// The 'any' address.
20 | pub const Any: Self = Self
21 | {
22 | sib_subnet_prefix: 0,
23 | sib_interface_id: 0,
24 | };
25 |
26 | /// The 'loopback' address.
27 | #[cfg(target_endian = "little")]
28 | pub const Loopback: Self = Self
29 | {
30 | sib_subnet_prefix: 0,
31 | sib_interface_id: 0x100000000000000,
32 | };
33 |
34 | /// The 'loopback' address.
35 | #[cfg(target_endian = "big")]
36 | pub const Loopback: Self = Self
37 | {
38 | sib_subnet_prefix: 0,
39 | sib_interface_id: 0x000000100000000,
40 | };
41 |
42 | /// Is 'any' address.
43 | #[inline(always)]
44 | pub fn is_any(&self) -> bool
45 | {
46 | self == &Self::Any
47 | }
48 |
49 | /// Is 'loopback' address.
50 | #[inline(always)]
51 | pub fn is_loopback(&self) -> bool
52 | {
53 | self == &Self::Loopback
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/socket/syscall/in6_addr.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Whilst this is present in libc, it does not support useful derives.
6 | #[derive(Copy, Clone, Eq)]
7 | #[repr(C)]
8 | pub union in6_addr
9 | {
10 | /// 16 bytes.
11 | pub s6_addr: [uint8_t; 16],
12 |
13 | /// 8 network endian 16-bit integers.
14 | pub s6_addr16: [uint16_t; 8],
15 |
16 | /// 4 network endian 32-bit integers.
17 | pub s6_addr32: [uint32_t; 4],
18 | }
19 |
20 | impl Default for in6_addr
21 | {
22 | #[inline(always)]
23 | fn default() -> Self
24 | {
25 | unsafe { zeroed() }
26 | }
27 | }
28 |
29 | impl Debug for in6_addr
30 | {
31 | #[inline(always)]
32 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
33 | {
34 | write!(f, "{:?}", unsafe { self.s6_addr })
35 | }
36 | }
37 |
38 | impl PartialEq for in6_addr
39 | {
40 | #[inline(always)]
41 | fn eq(&self, other: &Self) -> bool
42 | {
43 | unsafe { self.s6_addr == other.s6_addr }
44 | }
45 | }
46 |
47 | impl PartialOrd for in6_addr
48 | {
49 | #[inline(always)]
50 | fn partial_cmp(&self, other: &Self) -> Option
51 | {
52 | unsafe { self.s6_addr.partial_cmp(&other.s6_addr) }
53 | }
54 | }
55 |
56 | impl Ord for in6_addr
57 | {
58 | #[inline(always)]
59 | fn cmp(&self, other: &Self) -> Ordering
60 | {
61 | unsafe { self.s6_addr.cmp(&other.s6_addr) }
62 | }
63 | }
64 |
65 | impl Hash for in6_addr
66 | {
67 | #[inline(always)]
68 | fn hash(&self, hasher: &mut H)
69 | {
70 | unsafe { self.s6_addr.hash(hasher) }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/socket/syscall/in_addr.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Whilst this is present in libc, it does not support useful derives.
6 | #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | #[repr(C)]
8 | pub struct in_addr
9 | {
10 | /// Must a 32-bit integer in Network Endian form, not Native Endian form.
11 | pub s_addr: in_addr_t,
12 | }
13 |
--------------------------------------------------------------------------------
/src/socket/syscall/listen.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// Makes a bound socket a listener.
9 | ///
10 | /// On success, zero is returned.
11 | /// On error, `-1` is returned, and `errno` is set appropriately.
12 | ///
13 | /// The known errors that can be set in `errno` are:-
14 | ///
15 | /// * `EADDRINUSE`: Another socket is already listening on the same port.
16 | /// * `EBADF`: `sockfd` is not a valid descriptor.
17 | /// * `ENOTSOCK`: `sockfd` is not a socket file descriptor.
18 | /// * `EOPNOTSUPP`: The socket is not of a type that supports the `listen()` operation.
19 | pub(crate) fn listen(sockfd: c_int, backlog: c_int) -> c_int;
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/src/socket/syscall/mmsghdr.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[derive(Default, Debug, Clone)]
6 | #[repr(C)]
7 | pub(crate) struct mmsghdr
8 | {
9 | /// PosixMessage header.
10 | pub(crate) msg_hdr: msghdr,
11 |
12 | /// Number of received bytes for header.
13 | ///
14 | /// This field has the same value as the return value of a single `recvmsg()` call.
15 | pub(crate) msg_len: c_uint,
16 | }
17 |
--------------------------------------------------------------------------------
/src/socket/syscall/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 | use ::libc::c_char;
7 | use ::libc::c_uchar;
8 | use ::libc::c_uint;
9 | use ::libc::in_addr_t;
10 | use ::libc::in_port_t;
11 | use ::libc::ssize_t;
12 | use ::libc::timespec;
13 | use ::libc::unlink;
14 |
15 |
16 | include!("accept4.rs");
17 | include!("bind.rs");
18 | include!("cmsghdr.rs");
19 | include!("connect.rs");
20 | include!("getsockname.rs");
21 | include!("getsockopt.rs");
22 | include!("ib_addr.rs");
23 | include!("in_addr.rs");
24 | include!("in6_addr.rs");
25 | include!("listen.rs");
26 | include!("MSG_.rs");
27 | include!("mmsghdr.rs");
28 | include!("msghdr.rs");
29 | include!("recvfrom.rs");
30 | include!("recvmmsg.rs");
31 | include!("recvmsg.rs");
32 | include!("SCM_.rs");
33 | include!("sendmsg.rs");
34 | include!("setsockopt.rs");
35 | include!("socketpair.rs");
36 | include!("shutdown.rs");
37 | include!("SO_.rs");
38 | include!("sockaddr_ib.rs");
39 | include!("sockaddr_in.rs");
40 | include!("sockaddr_in6.rs");
41 | include!("sockaddr_un.rs");
42 | include!("sockaddr_storage.rs");
43 | include!("socket.rs");
44 | include!("SOL_.rs");
45 | include!("TCP_.rs");
46 | include!("ucred.rs");
47 |
--------------------------------------------------------------------------------
/src/socket/syscall/recvmsg.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | pub(crate) fn recvmsg(sockfd: RawFd, msg: *mut msghdr, flags: c_int) -> ssize_t;
9 | }
10 |
--------------------------------------------------------------------------------
/src/socket/syscall/sendmsg.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | pub(crate) fn sendmsg(sockfd: RawFd, msg: *const msghdr, flags: c_int) -> ssize_t;
9 | }
10 |
--------------------------------------------------------------------------------
/src/socket/syscall/setsockopt.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// Sets a socket option.
9 | ///
10 | /// On success, zero is returned.
11 | /// On error, `-1` is returned, and `errno` is set appropriately.
12 | ///
13 | /// The known errors that can be set in `errno` are:-
14 | ///
15 | /// * `EBADF`: The argument `sockfd` is not a valid descriptor.
16 | /// * `EFAULT`: The address pointed to by `optval` is not in a valid part of the process address space.
17 | /// * `EINVAL`: `optlen` is invalid, or there is an invalid value in `optval`.
18 | /// * `ENOPROTOOPT`: The option is unknown at the level indicated.
19 | /// * `ENOTSOCK`: The argument `sockfd` is a file, not a socket.
20 | pub(crate) fn setsockopt(sockfd: RawFd, level: c_int, optname: c_int, optval: *const c_void, optlen: socklen_t) -> c_int;
21 | }
22 |
--------------------------------------------------------------------------------
/src/socket/syscall/shutdown.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// `shutdown()` is most useful for initiating TCP's `FIN` state machine, and so freeing up resources inside Linux.
9 | ///
10 | /// There is very little advantages in half-close, especially when sockets are used with upper layer protocols such as TLS, as these can do reads when a logical write is required, and vice-versa.
11 | ///
12 | /// `how` is one of `SHUT_RD` (shutdown read), `SHUT_WR` (shutdown write) or `SHUT_RDWR` (shutdown read and write).
13 | ///
14 | /// On success, zero is returned.
15 | /// On error, `-1` is returned, and `errno` is set appropriately.
16 | ///
17 | /// The known errors that can be set in `errno` are:-
18 | ///
19 | /// * `EBADF`: `sockfd` is not a valid file descriptor.
20 | /// * `EINVAL`: An invalid value was specified in `how`.
21 | /// * `ENOTCONN`: The specified socket is not connected.
22 | /// * `ENOTSOCK`: The file descriptor `sockfd` does not refer to a socket.
23 | pub(crate) fn shutdown(sockfd: RawFd, how: c_int) -> c_int;
24 | }
25 |
26 | /// Half-close read.
27 | #[allow(dead_code)]
28 | pub(crate) const SHUT_RD: c_int = 0;
29 |
30 | /// Half-close write.
31 | #[allow(dead_code)]
32 | pub(crate) const SHUT_WR: c_int = 1;
33 |
34 | /// Close read and write.
35 | pub(crate) const SHUT_RDWR: c_int = 2;
36 |
--------------------------------------------------------------------------------
/src/socket/syscall/sockaddr_ib.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Infiniband socket address structure.
6 | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | #[repr(C)]
8 | pub struct sockaddr_ib
9 | {
10 | /// Socket address family.
11 | sib_family: sa_family_t,
12 |
13 | /// Must a 16-bit integer in Network Endian form, not Native Endian form.
14 | pub sib_pkey: u16,
15 |
16 | /// Must a 32-bit integer in Network Endian form, not Native Endian form.
17 | pub sib_flowinfo: u32,
18 |
19 | /// Address.
20 | pub sib_addr: ib_addr,
21 |
22 | /// Must a 64-bit integer in Network Endian form, not Native Endian form.
23 | pub sib_sid: u64,
24 |
25 | /// Must a 64-bit integer in Network Endian form, not Native Endian form.
26 | pub sib_sid_mask: u64,
27 |
28 | /// Must a 64-bit integer in *Native Endian form*.
29 | pub sib_scope_id: u64,
30 | }
31 |
32 | impl Default for sockaddr_ib
33 | {
34 | #[inline(always)]
35 | fn default() -> Self
36 | {
37 | Self
38 | {
39 | sib_family: AF_IB as sa_family_t,
40 | sib_pkey: 0,
41 | sib_flowinfo: 0,
42 | sib_addr: ib_addr::default(),
43 | sib_sid: 0,
44 | sib_sid_mask: 0,
45 | sib_scope_id: 0,
46 | }
47 | }
48 | }
49 |
50 | impl SocketData for sockaddr_ib
51 | {
52 | #[inline(always)]
53 | fn family(&self) -> sa_family_t
54 | {
55 | self.sib_family
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/socket/syscall/socketpair.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// The `socketpair()` call creates an unnamed pair of connected sockets in the specified `domain`, of the specified `type_`, and using the optionally specified `protocol`.
9 | ///
10 | /// The values of `domain`, `type_` and `protocol` are the same as for `socket()`.
11 | ///
12 | /// The file descriptors used in referencing the new sockets are returned in `sv[0]` and `sv[1]`.
13 | ///
14 | /// The two sockets are indistinguishable.
15 | ///
16 | /// On Linux, the only supported domain for this call is `AF_UNIX` (or synonymously, `AF_LOCAL`).
17 | ///
18 | /// Since Linux 2.6.27, `socketpair()` supports the `SOCK_NONBLOCK` and `SOCK_CLOEXEC` flags.
19 | ///
20 | /// On success, zero is returned.
21 | /// On error, `-1` is returned, and `errno` is set appropriately.
22 | ///
23 | /// The known errors that can be set in `errno` are:-
24 | ///
25 | /// * `EAFNOSUPPORT`: The specified address family is not supported on this machine.
26 | /// * `EFAULT`: The address `sv` does not specify a valid part of the process address space.
27 | /// * `EMFILE`: Too many descriptors are in use by this process.
28 | /// * `ENFILE`: The system limit on the total number of open files has been reached.
29 | /// * `EOPNOTSUPP`: The specified `protocol` does not support creation of socket pairs.
30 | /// * `EPROTONOSUPPORT`: The specified `protocol` is not supported on this machine.
31 | pub(crate) fn socketpair(domain: c_int, type_: c_int, protocol: c_int, sv: *mut [c_int; 2]) -> c_int;
32 | }
33 |
--------------------------------------------------------------------------------
/src/socket/syscall/ucred.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[repr(C)]
6 | pub(crate) struct ucred
7 | {
8 | pid: pid_t,
9 | uid: uid_t,
10 | gid: gid_t,
11 | }
12 |
--------------------------------------------------------------------------------
/src/terminal/BitsPerByte.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Abstracts bits per byte.
6 | ///
7 | /// Defaults to 8.
8 | #[derive(EnumIter, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9 | #[cfg_attr(not(any(target_os = "ios", target_os = "macos")), repr(u32))]
10 | #[cfg_attr(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "32"), repr(u32))]
11 | #[cfg_attr(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "64"), repr(u64))]
12 | pub enum BitsPerByte
13 | {
14 | /// Five.
15 | Five = CS5,
16 |
17 | /// Six.
18 | Six = CS6,
19 |
20 | /// Seven.
21 | Seven = CS7,
22 |
23 | /// Eight.
24 | Eight = CS8,
25 | }
26 |
27 | impl Into for BitsPerByte
28 | {
29 | #[inline(always)]
30 | fn into(self) -> tcflag_t
31 | {
32 | self as tcflag_t
33 | }
34 | }
35 |
36 | impl Default for BitsPerByte
37 | {
38 | #[inline(always)]
39 | fn default() -> Self
40 | {
41 | BitsPerByte::Eight
42 | }
43 | }
44 |
45 | impl MultipleBits for BitsPerByte
46 | {
47 | const Bitmask: tcflag_t = CSIZE;
48 |
49 | #[inline(always)]
50 | fn transmute_from_clean_mode_flags(clean_mode_flags: tcflag_t) -> Self
51 | {
52 | unsafe { transmute(clean_mode_flags) }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/terminal/ControlModeFlagSettings.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents settings for output mode flags.
6 | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
7 | pub struct ControlModeFlagSettings
8 | {
9 | /// Bits per byte.
10 | pub bits_per_byte: Option,
11 |
12 | /// How many stop bits?
13 | pub stop_bits: Option,
14 |
15 | /// Parity.
16 | pub parity: Option,
17 |
18 | /// Miscellaneous.
19 | pub miscellaneous: MiscellaneousControlModeFlagSettings,
20 | }
21 |
22 | impl Default for ControlModeFlagSettings
23 | {
24 | #[inline(always)]
25 | fn default() -> Self
26 | {
27 | Self
28 | {
29 | bits_per_byte: Some(BitsPerByte::default()),
30 | stop_bits: Some(StopBits::default()),
31 | parity: Some(Parity::default()),
32 | miscellaneous: MiscellaneousControlModeFlagSettings::default(),
33 | }
34 | }
35 | }
36 |
37 | impl ControlModeFlagSettings
38 | {
39 | #[inline(always)]
40 | pub(crate) fn change_mode_flags(&self, terminal_options: &mut termios)
41 | {
42 | let existing_flags = terminal_options.c_cflag;
43 |
44 | let mut new_flags = existing_flags;
45 | new_flags = MultipleBits::change_mode_flags(self.bits_per_byte, new_flags);
46 | new_flags = MultipleBits::change_mode_flags(self.stop_bits, new_flags);
47 | new_flags = MultipleBits::change_mode_flags(self.parity, new_flags);
48 | new_flags = self.miscellaneous.change_mode_flags(new_flags);
49 |
50 | terminal_options.c_cflag = new_flags;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/terminal/FlagSetting.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// On or off.
6 | ///
7 | /// Default is `FlagSetting::Off`.
8 | #[derive(EnumIter, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9 | pub enum FlagSetting
10 | {
11 | /// Set on.
12 | On,
13 |
14 | /// Set off.
15 | Off,
16 | }
17 |
18 | impl Into for FlagSetting
19 | {
20 | #[inline(always)]
21 | fn into(self) -> bool
22 | {
23 | use self::FlagSetting::*;
24 |
25 | match self
26 | {
27 | On => true,
28 | Off => false,
29 | }
30 | }
31 | }
32 |
33 | impl From for FlagSetting
34 | {
35 | #[inline(always)]
36 | fn from(value: bool) -> Self
37 | {
38 | use self::FlagSetting::*;
39 |
40 | match value
41 | {
42 | true => On,
43 | false => Off,
44 | }
45 | }
46 | }
47 |
48 | impl Default for FlagSetting
49 | {
50 | #[inline(always)]
51 | fn default() -> Self
52 | {
53 | FlagSetting::Off
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/terminal/MultipleBits.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | trait MultipleBits: Default + Copy + Into
6 | {
7 | const Bitmask: tcflag_t = 0;
8 |
9 | #[inline(always)]
10 | fn from_mode_flags(mode_flags: tcflag_t) -> Self
11 | {
12 | Self::transmute_from_clean_mode_flags(mode_flags | Self::Bitmask)
13 | }
14 |
15 | fn transmute_from_clean_mode_flags(clean_mode_flags: tcflag_t) -> Self;
16 |
17 | #[inline(always)]
18 | fn change_mode_flags(this: Option, current_flags: tcflag_t) -> tcflag_t
19 | {
20 | match this
21 | {
22 | None => current_flags,
23 | Some(multiple_bits) =>
24 | {
25 | let bits = multiple_bits.into();
26 | (current_flags & !Self::Bitmask) | bits
27 | },
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/terminal/StopBits.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Abstracts the number of stop bits.
6 | ///
7 | /// Defaults to one.
8 | #[derive(EnumIter, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9 | #[cfg_attr(not(any(target_os = "ios", target_os = "macos")), repr(u32))]
10 | #[cfg_attr(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "32"), repr(u32))]
11 | #[cfg_attr(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "64"), repr(u64))]
12 | pub enum StopBits
13 | {
14 | /// One.
15 | One = 0,
16 |
17 | /// Two.
18 | Two = CSTOPB,
19 | }
20 |
21 | impl Into for StopBits
22 | {
23 | #[inline(always)]
24 | fn into(self) -> tcflag_t
25 | {
26 | self as tcflag_t
27 | }
28 | }
29 |
30 | impl Default for StopBits
31 | {
32 | #[inline(always)]
33 | fn default() -> Self
34 | {
35 | StopBits::One
36 | }
37 | }
38 |
39 | impl MultipleBits for StopBits
40 | {
41 | const Bitmask: tcflag_t = CSTOPB;
42 |
43 | #[inline(always)]
44 | fn transmute_from_clean_mode_flags(clean_mode_flags: tcflag_t) -> Self
45 | {
46 | use self::StopBits::*;
47 |
48 | match clean_mode_flags & Self::Bitmask != 0
49 | {
50 | true => Two,
51 | false => One,
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/terminal/TerminalSettingsError.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// An error that can in a terminal.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | pub enum TerminalSettingsError
8 | {
9 | /// Not a terminal.
10 | NotATerminal(Errno),
11 |
12 | /// Could not set terminal attributes.
13 | CouldNotSetTerminalAttributes(Errno),
14 | }
15 |
16 | impl Display for TerminalSettingsError
17 | {
18 | #[inline(always)]
19 | fn fmt(&self, f: &mut Formatter) -> fmt::Result
20 | {
21 | ::fmt(self, f)
22 | }
23 | }
24 |
25 | impl error::Error for TerminalSettingsError
26 | {
27 | #[inline(always)]
28 | fn source(&self) -> Option<&(dyn error::Error + 'static)>
29 | {
30 | use self::TerminalSettingsError::*;
31 |
32 | match self
33 | {
34 | NotATerminal(_) => None,
35 |
36 | CouldNotSetTerminalAttributes(_) => None,
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/terminal/WhenToChangeTerminalAttributes.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// When to change the terminal attributes.
6 | #[derive(EnumIter, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | #[repr(i32)]
8 | pub enum WhenToChangeTerminalAttributes
9 | {
10 | /// Change immediately.
11 | Now = TCSANOW,
12 |
13 | /// Change after waiting until all queued output has been written.
14 | ///
15 | /// You should usually use this option when changing parameters that affect output.
16 | Drain = TCSADRAIN,
17 |
18 | /// Change after waiting until all queued output has been written and after discarding all queued input.
19 | Flush = TCSAFLUSH,
20 | }
21 |
22 | impl WhenToChangeTerminalAttributes
23 | {
24 | #[inline(always)]
25 | pub(crate) fn flags(self, ignore_control_flags: bool) -> c_int
26 | {
27 | let flags = self as c_int;
28 | if unlikely!(ignore_control_flags)
29 | {
30 | flags | TCSASOFT
31 | }
32 | else
33 | {
34 | flags
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/terminal/c/EXT.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[allow(dead_code)] pub(crate) const EXTA: speed_t = B19200;
6 |
7 | #[allow(dead_code)] pub(crate) const EXTB: speed_t = B38400;
8 |
--------------------------------------------------------------------------------
/src/terminal/c/NCCS.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[cfg(all(any(target_os = "android", target_os = "fuschia", target_os = "linux"), not(target_arch = "powerpc")))] pub(crate) const NCCS: usize = 32;
6 | #[cfg(all(any(target_os = "android", target_os = "fuschia", target_os = "linux"), target_arch = "powerpc"))] pub(crate) const NCCS: usize = 19;
7 | #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "openbsd"))] pub(crate) const NCCS: usize = 20;
8 |
--------------------------------------------------------------------------------
/src/terminal/c/TCSA.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | pub(crate) const TCSANOW: c_int = 0;
6 |
7 | pub(crate) const TCSADRAIN: c_int = 1;
8 |
9 | pub(crate) const TCSAFLUSH: c_int = 2;
10 |
11 | #[cfg(not(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "openbsd")))] pub(crate) const TCSASOFT: c_int = 0x00;
12 | #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "openbsd"))] pub(crate) const TCSASOFT: c_int = 0x10;
13 |
--------------------------------------------------------------------------------
/src/terminal/c/_POSIX_VDISABLE.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | pub(crate) const _POSIX_VDISABLE: cc_t = 0;
6 |
--------------------------------------------------------------------------------
/src/terminal/c/cc_t.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | pub(crate) type cc_t = c_uchar;
6 |
--------------------------------------------------------------------------------
/src/terminal/c/cfgetispeed.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | #[allow(dead_code)] pub(crate) fn cfgetispeed(termios_p: *const termios) -> speed_t;
9 | }
10 |
--------------------------------------------------------------------------------
/src/terminal/c/cfgetospeed.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | pub(crate) fn cfgetospeed(termios_p: *const termios) -> speed_t;
9 | }
10 |
--------------------------------------------------------------------------------
/src/terminal/c/cfmakeraw.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | #[allow(dead_code)] pub(crate) fn cfmakeraw(termios_p: *mut termios);
9 | }
10 |
--------------------------------------------------------------------------------
/src/terminal/c/cfsetispeed.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | #[allow(dead_code)] pub(crate) fn cfsetispeed(termios_p: *mut termios, speed: speed_t) -> c_int;
9 | }
10 |
--------------------------------------------------------------------------------
/src/terminal/c/cfsetospeed.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | #[allow(dead_code)] pub(crate) fn cfsetospeed(termios_p: *mut termios, speed: speed_t) -> c_int;
9 | }
10 |
--------------------------------------------------------------------------------
/src/terminal/c/cfsetspeed.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// Linux and BSD extension that sets input baud rate and output baud rate to the same value.
9 | ///
10 | /// Linux always forces the two baud rates to the same value in any event.
11 | pub(crate) fn cfsetspeed(termios_p: *mut termios, speed: speed_t) -> c_int;
12 | }
13 |
--------------------------------------------------------------------------------
/src/terminal/c/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 | use ::libc::c_uchar;
7 | use ::libc::c_uint;
8 |
9 |
10 | include!("_POSIX_VDISABLE.rs");
11 | include!("B.rs");
12 | include!("C.rs");
13 | include!("cc_t.rs");
14 | include!("cfgetispeed.rs");
15 | include!("cfgetospeed.rs");
16 | include!("cfmakeraw.rs");
17 | include!("cfsetispeed.rs");
18 | include!("cfsetospeed.rs");
19 | include!("cfsetspeed.rs");
20 | include!("EXT.rs");
21 | include!("I.rs");
22 | include!("L.rs");
23 | include!("NCCS.rs");
24 | include!("O.rs");
25 | include!("speed_t.rs");
26 | include!("TCSA.rs");
27 | include!("tcdrain.rs");
28 | include!("tcflag_t.rs");
29 | include!("tcflow.rs");
30 | include!("tcflush.rs");
31 | include!("tcgetattr.rs");
32 | include!("tcgetsid.rs");
33 | include!("tcsendbreak.rs");
34 | include!("tcsetattr.rs");
35 | include!("termios.rs");
36 | include!("V.rs");
37 |
--------------------------------------------------------------------------------
/src/terminal/c/speed_t.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[cfg(not(any(target_os = "ios", target_os = "macos")))] pub(crate) type speed_t = c_uint;
6 | #[cfg(any(target_os = "ios", target_os = "macos"))] pub(crate) type speed_t = c_ulong;
7 |
--------------------------------------------------------------------------------
/src/terminal/c/tcdrain.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | pub(crate) fn tcdrain(fd: c_int) -> c_int;
9 | }
10 |
--------------------------------------------------------------------------------
/src/terminal/c/tcflag_t.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[cfg(not(any(target_os = "ios", target_os = "macos")))] pub(crate) type tcflag_t = c_uint;
6 | #[cfg(any(target_os = "ios", target_os = "macos"))] pub(crate) type tcflag_t = c_ulong;
7 |
--------------------------------------------------------------------------------
/src/terminal/c/tcflow.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | pub(crate) fn tcflow(fd: c_int, action: c_int) -> c_int;
9 | }
10 |
11 | pub(crate) const TCOOFF: c_int = 1;
12 |
13 | pub(crate) const TCOON: c_int = 2;
14 |
15 | pub(crate) const TCIOFF: c_int = 3;
16 |
17 | pub(crate) const TCION: c_int = 4;
18 |
--------------------------------------------------------------------------------
/src/terminal/c/tcflush.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | pub(crate) fn tcflush(fd: c_int, queue_selector: c_int) -> c_int;
9 | }
10 |
11 | #[cfg(any(target_os = "android", target_os = "fuschia", target_os = "linux"))] pub(crate) const TCIFLUSH: c_int = 0;
12 | #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "openbsd"))] pub(crate) const TCIFLUSH: c_int = 1;
13 |
14 | #[cfg(any(target_os = "android", target_os = "fuschia", target_os = "linux"))] pub(crate) const TCOFLUSH: c_int = 1;
15 | #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "openbsd"))] pub(crate) const TCOFLUSH: c_int = 2;
16 |
17 | #[cfg(any(target_os = "android", target_os = "fuschia", target_os = "linux"))] pub(crate) const TCIOFLUSH: c_int = 2;
18 | #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "openbsd"))] pub(crate) const TCIOFLUSH: c_int = 3;
19 |
--------------------------------------------------------------------------------
/src/terminal/c/tcgetattr.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 | #[link(name = "c")]
5 | extern "C"
6 | {
7 | pub(crate) fn tcgetattr(fd: c_int, termios_p: *mut termios) -> c_int;
8 | }
9 |
--------------------------------------------------------------------------------
/src/terminal/c/tcgetsid.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | pub(crate) fn tcgetsid(fd: c_int) -> pid_t;
9 | }
10 |
--------------------------------------------------------------------------------
/src/terminal/c/tcsendbreak.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | pub(crate) fn tcsendbreak(fd: c_int, duration: c_int) -> c_int;
9 | }
10 |
--------------------------------------------------------------------------------
/src/terminal/c/tcsetattr.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | pub(crate) fn tcsetattr(fd: c_int, optional_actions: c_int, termios_p: *const termios) -> c_int;
9 | }
10 |
--------------------------------------------------------------------------------
/src/timerfd/TimerSetChoices.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Interpretation of time values when setting timer.
6 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 | #[repr(i32)]
8 | pub enum TimerSetChoices
9 | {
10 | /// Time values are a relative offset (duration).
11 | ///
12 | /// This is the default.
13 | Relative = 0,
14 |
15 | /// Time values are an absolute.
16 | Absolute = TFD_TIMER_ABSTIME,
17 |
18 | /// Cancels reads if the realtime clock is adjusted.
19 | ///
20 | /// Only works for `TimerClock::RealTime` or `TimerClock::RealTimeAlarm`.
21 | AbsoluteCancellingReadsOnFileDescriptorIfRealTimeClockIsAdjusted = TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET,
22 | }
23 |
24 | impl Default for TimerSetChoices
25 | {
26 | #[inline(always)]
27 | fn default() -> Self
28 | {
29 | TimerSetChoices::Relative
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/timerfd/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 | use self::syscall::*;
7 | use ::libc::timespec;
8 |
9 |
10 | mod syscall;
11 |
12 |
13 | include!("TimerClock.rs");
14 | include!("TimerFileDescriptor.rs");
15 | include!("TimerSetChoices.rs");
16 |
--------------------------------------------------------------------------------
/src/timerfd/syscall/itimerspec.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | /// Represents a timer value.
6 | #[repr(C)]
7 | pub struct itimerspec
8 | {
9 | /// `interval`.
10 | pub it_interval: timespec,
11 |
12 | /// `value`.
13 | pub it_value: timespec,
14 | }
15 |
--------------------------------------------------------------------------------
/src/timerfd/syscall/mod.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | use super::*;
6 |
7 |
8 | include!("itimerspec.rs");
9 | include!("timerfd_create.rs");
10 | include!("timerfd_settime.rs");
11 | include!("timerfd_gettime.rs");
12 |
--------------------------------------------------------------------------------
/src/timerfd/syscall/timerfd_gettime.rs:
--------------------------------------------------------------------------------
1 | // This file is part of file-descriptors. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT. No part of file-descriptors, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2 | // Copyright © 2018-2019 The developers of file-descriptors. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/file-descriptors/master/COPYRIGHT.
3 |
4 |
5 | #[link(name = "c")]
6 | extern "C"
7 | {
8 | /// `timerfd_gettime()` returns, in `curr_value`, an `itimerspec` structure that contains the current setting of the timer referred to by the file descriptor `fd`.
9 | ///
10 | /// The `it_value` field returns the amount of time until the timer will next expire.
11 | /// If both fields of this structure are zero, then the timer is currently disarmed.
12 | /// This field always contains a relative value, regardless of whether the `TFD_TIMER_ABSTIME` flag was specified when setting the timer.
13 | ///
14 | /// The `it_interval` field returns the interval of the timer.
15 | /// If both fields of this structure are zero, then the timer is set to expire just once, at the time specified by `curr_value.it_value`.
16 | ///
17 | /// On success, `timerfd_gettime()` returns `0`.
18 | /// On error, `-1` is returned and `errno` is set to indicate the error.
19 | ///
20 | /// The known errors that can be set in `errno` are:-
21 | /// * `EBADF`: `fd` is not a valid file descriptor.
22 | /// * `EFAULT`: `curr_value` is not a valid pointer.
23 | /// * `EINVAL`: `fd` is not a valid timerfd file descriptor.
24 | pub(crate) fn timerfd_gettime(fd: RawFd, curr_value: *mut itimerspec) -> c_int;
25 | }
26 |
--------------------------------------------------------------------------------