Commit Graph

23 Commits

Author SHA1 Message Date
SteveLauC
6961f0fabd
refactor: cfg for test/* (#2230)
* refactor: cfg for test/*

* one more netbsdlike

* more cfg
2023-12-09 16:15:41 +00:00
Jonathan Woollett-Light
7e16e32c93
feat: Safer poll timeout (#1876) 2023-11-23 01:15:30 +00:00
Alan Somers
ea888247b7
Relax lifetime requirements for PollFd::new (#2134)
* Relax lifetime requirements for PollFd::new

Fixes #2118

* Take BorrowedFd as the argument for PollFd::new

&AsFd didn't work because there are 'static types, like std::fs::File,
which implement AsFd.  The created BorrowedFd type within the
PollFd::new method would have a very brief lifetime, but the PhantomData
would capture the lifetime of the std::fs::File.  Taking BorrowFd<'fd>
argument makes the lifetime explicit.

* fix legacy comment

---------

Co-authored-by: Steve Lau <stevelauc@outlook.com>
2023-10-01 11:30:52 +00:00
Jonathan Woollett-Light
8ad064d7b9
feat: I/O safety pipe, pipe2 & write (#2100) 2023-09-30 07:52:11 +00:00
Steve Lau
47ecc9a1d0 feat: I/O safety for 'sys/poll' 2022-12-11 14:04:13 +08:00
Costin-Robert Sin
3e6cb639f0 Fix all formating problems to pass CI formating test
Signed-off-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
2022-06-24 00:35:52 +03:00
Stefano Garzarella
c3081e4896 ppoll: make sigmask parameter optional
ppoll(2) supports 'sigmask' as NULL. In that case no signal mask
manipulation is performed.

Let's make `sigmask` parameter of `nix::poll::ppoll` optional
to allow that behaviour.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-06-09 09:09:23 +02:00
Conrad Meyer
b16e70eebf Fix #411 - Provide accessors for 'events' in PollFd
Test: `cargo test --test test test_pollfd_events`
2021-09-19 17:14:30 -07:00
Conrad Meyer
b0b7beb2a8 Implement AsRawFd for PollFd
Implement the trait on PollFd, providing an `as_raw_fd()` accessor to
get the RawFd associated with the PollFd.

Subsumes #1147, #1286.  Closes #1146.

Test: `cargo test --test test test_pollfd_fd`
2021-09-07 08:57:17 -07:00
Alan Somers
2d796eba38 Collapse Error into Errno
Now that Nix's weird error types are eliminated, there's no reason not
to simply use Errno as the Error type.
2021-07-07 20:49:29 -06:00
Alan Somers
6511d02414 Overhaul Nix's error types
For many of Nix's consumers it be convenient to easily convert a Nix
error into a std::io::Error.  That's currently not possible because of
the InvalidPath, InvalidUtf8, and UnsupportedOperation types that have
no equivalent in std::io::Error.

However, very few of Nix's public APIs actually return those unusual
errors.  So a more useful API would be for Nix's standard error type to
implement Into<std::io::Error>.

This commit makes Error a simple NewType around Errno.  For most
functions it's a drop-in replacement.  There are only three exceptions:

* clearenv now returns a bespoke error type.  It was the only Nix
  function whose error couldn't be cleanly mapped onto an Errno.

* sys::signal::signal now returns Error(Errno::ENOTSUP) instead of
  Error::UnsupportedOperation when the user passes an incompatible
  argument to `handler`.

* When a NixPath exceeds PATH_MAX, it will now return
  Error(Errno::ENAMETOOLONG) instead of Error::InvalidPath.

In the latter two cases there is now some abiguity about whether the
error code was generated by Nix or by the OS.  But I think the ambiguity
is worth it for the sake of being able to implement Into<io::Error>.

This commit also introduces Error::Sys() as a migration aid.  Previously
that as an enum variant.  Now it's a function, but it will work in many
of the same contexts as the original.

Fixes #1155
2021-07-07 20:49:28 -06:00
Alan Somers
7c755e6025 Fix a non_fmt_panic warning with Rustc 1.52.0 2021-02-20 14:49:12 -07:00
Alan Somers
8b2374c4fd Make the poll tests resilient against signals
When run in Cirrus-CI's environment, the tests generate copious SIGRT_1
signals.  This commit ensures that the poll tests will retry on EINTR.
2020-12-06 22:23:30 -07:00
Mikail Bagishov
cbcc42deb6
Support nullable timeout in ppoll 2020-07-26 23:19:57 +03:00
Bryant Mairs
b5c04adbd7 Remove test of impl Debug for PollFd
As this is now derived, having a test is unnecessary
2019-06-09 11:31:46 -07:00
Amanjeev Sethi
1b2fadd21a PollFd event flags renamed to PollFlags from EventFlags.
Most of the EventFlags have been renamed already, but Poll was the only one remaining. This commit fixes that.

Issue 317 https://github.com/nix-rust/nix/issues/317
2019-02-12 15:25:47 -05:00
Tom Pusateri
d1395511a6 Allow 'cargo test' to complete successfully on NetBSD 8.0.
Some tests have been disabled and will need further review.
2018-12-16 22:16:27 -05:00
Zhouyu Qian
5e2b582662
Implement Debug trait for PollFd
This is useful when using printf-style debugging to observe the variables of
the program.

Also includes a test.

Fixes #885.
2018-04-19 19:38:20 -07:00
Bryant Mairs
e1baab9dc1 Upgrade to Bitflags 1.0
The libc_bitflags! macro was replaced with a non-recursive one supporting
only public structs. I could not figure out how to make the old macro work
with the upgrade, so I reworked part of the bitflags! macro directly to suit
our needs, much as the original recursive macro was made. There are no uses
of this macro for non-public structs, so this is not a problem for internal code.
2017-12-02 10:46:34 -08:00
Alan Somers
5810b9424d Add a test for ppoll 2017-10-14 17:42:51 -06:00
Bryant Mairs
80453b9139 Remove revents from PollFd::new
revents is an output field so regardless of what value it is set to it
will be overwritten by many of the function calls that take a PollFd.
The only value that makes sense for the caller to pass in in
`EventFlags::empty()` so we just hardcode that instead of making the
caller do it.
2017-03-02 09:52:33 -08:00
Philipp Matthias Schaefer
93dc2387bd Use libc in poll.rs 2016-08-31 20:17:55 +02:00
Utkarsh Kukreti
cec5c6157b Add everything from poll.h. 2016-01-25 17:50:39 -05:00