Commit Graph

128 Commits

Author SHA1 Message Date
Wesley Wiser 5343302970
Update use of libc::timespec to prepare for future libc version (#55)
In a future release of the `libc` crate, `libc::timespec` will contain
private padding fields on `*-linux-musl` targets and so the struct will
no longer be able to be created using the literal initialization syntax.

Update `TS_ZERO` to create a value by initializing an array of the
correct size to `0` and then transmuting to `libc::timespec`. Update
struct literal use of `libc::timespec` to initialize to `TS_ZERO` and
then manually update the appropriate fields. Also updates a raw syscall
to use the libc function instead as on musl 1.2, it correctly handles
`libc::timespec` values which, in musl 1.2, are always 16 bytes in
length regardless of platform.
2022-12-03 23:04:37 +09:00
John Nunley 00e7eefc4d
Add error message for Wepoll (#54)
* Add error message for Wepoll

* Avoid unsupported error kind where it is not supported
2022-11-30 20:26:28 -08:00
Taiki Endo 0b45549097
Test x86_64-pc-windows-gnu with Wine on CI (#53) 2022-11-30 23:21:01 +09:00
Taiki Endo 6f459f89a9 Use std::os::raw::c_int instead of std::ffi::c_int 2022-11-29 22:21:43 +09:00
John Nunley 8982599ddf
Port to windows-sys (#47) 2022-11-26 20:50:12 -08:00
Taiki Endo bf6cbcc31c Fix build error on solarish 2022-10-24 00:13:27 +09:00
Taiki Endo de312d15b6 Reduce size of sys::Events 2022-08-21 23:40:10 +09:00
Taiki Endo b9cce6645c Apply doc(cfg(...)) on platform-specific APIs 2022-08-21 19:47:00 +09:00
John Nunley 323473ec1a
Expose raw handles for the `Poller` (#39)
* expose raw handles

* add comment explaining no_*
2022-08-18 09:52:28 -07:00
Taiki Endo 055e2711ae Ignore clippy::useless_conversion and clippy::unnecessary_cast lints 2022-01-09 02:00:40 +09:00
Taiki Endo a12be08c97 Fix MSRV 2022-01-09 01:58:56 +09:00
Taiki Endo dec94cb423 Clean up CI config 2022-01-09 01:50:42 +09:00
Taiki Endo 4ac15ff339
Merge pull request #26 from Kestrer/master
Support VxWorks, Fuchsia and other Unix systems by using poll
2021-09-11 18:09:28 +09:00
Kestrer 597b6aed86 Add concurrent modification tests 2021-09-04 19:19:02 +01:00
Kestrer ee13911717 Remove `extra_traits` libc feature 2021-09-04 17:58:56 +01:00
Kestrer 9c257ccef6 Cast to `nfds_t` instead of `u64` in `poll` 2021-09-04 17:47:54 +01:00
Kestrer c174c9b7bb Prevent timeout overflow for poll and wepoll 2021-05-26 10:33:24 +01:00
Kestrer e0c0032cc0 swap_remove deleted file descriptors in poll backend 2021-05-26 10:25:24 +01:00
Philip Degarmo 2295ca07b8 Switch wepoll-sys to wepoll-ffi to reduce licenses used in dependency tree (discussed in #35) 2021-05-25 22:56:05 -07:00
Koxiaet a04a265f9b Merge branch 'master' 2021-01-03 10:19:51 +00:00
Taiki Endo c009653b99 Replace deprecated compare_and_swap with compare_exchange 2020-12-24 21:18:55 +09:00
Koxiaet 20c1e19c46 Have notifications break poll's operation loop 2020-12-18 15:03:59 +00:00
Koxiaet dd15b4cd8a Add logging to poll backend 2020-12-18 14:33:05 +00:00
Koxiaet e0789a8ee0 Make poll's poller modifications interrupt `wait` 2020-12-18 14:18:03 +00:00
Koxiaet 2fc0831d40 Use poll on VxWorks, Fuchsia and other Unix systems 2020-12-17 18:56:48 +00:00
Mike Zeller 6f778cddf1 port_dissociate should be aware of ENOENT 2020-10-19 22:19:12 +00:00
Stjepan Glavina 3a3020bb5c Use as_ptr and as_mut_ptr 2020-10-19 00:24:56 +02:00
Stjepan Glavina f4ee76fb32 Bump to v2.0.1 2020-10-09 14:10:22 +02:00
Stjepan Glavina b562ab84ea Use notified flag to make timeouts correct 2020-10-02 18:31:00 +02:00
Stjepan Glavina a3c748bcd0 Use more explicit type conversions 2020-10-02 18:19:15 +02:00
Stjepan Glavina 8b656241d5 Use saturating_add to prevent overflow 2020-10-02 18:17:45 +02:00
Stjepan Glavina d4667889b4 Switch to wepoll-sys 2020-10-02 17:41:55 +02:00
Stjepan Glavina 0a299cf060 Small cleanup 2020-10-02 17:34:53 +02:00
Yorick Peterse ba05307af1
Separate adding and modifying of file descriptors
This replaces Poller.insert() and Poller.interest() with Poller.add()
and Poller.modify(), and renames Poller.remove() to Poller.delete().

The method Poller.add() is used for adding a new file descriptor, while
Poller.modify() is used for updating an existing one. Poller.remove() is
renamed to Poller.delete() so the naming scheme of these methods follows
that of epoll, wepoll, etc.

This new setup means that adding a new socket only requires a single
call of Poller.add(), instead of a combination of Poller.insert() and
Poller.interest(). This reduces the amount of system calls necessary,
and leads to a more pleasant API.

On systems that use kqueue or ports, the behaviour of Poller.add() and
Poller.modify() is the same. This is because on these systems adding an
already existing file descriptor will just update its configuration.
This however is an implementation detail and should not be relied upon
by users.

Migrating to this new API is pretty simple, simply replace this:

    poller.insert(&socket);
    poller.interest(&socket, event);

With this:

    poller.add(&socket, event);

And for cases where Poller.interest() was used for updating an existing
file descriptor, simply replace it will a call to Poller.modify().

See https://github.com/stjepang/polling/issues/16 and
https://github.com/stjepang/polling/pull/17 for more information.
2020-10-01 21:50:59 +02:00
Yorick Peterse 4e5c3ce836
Don't automatically make descriptors non-blocking
This adds redundant system call overhead for file descriptors which have
already been turned into non-blocking file descriptors. In addition, the
polling crate doesn't need to implement platform specific code for
enabling non-blocking mode. Instead, users of polling can do so using
(for example) standard library methods such as
TcpListener.set_nonblocking().

See https://github.com/stjepang/polling/issues/16 for more information.
2020-10-01 20:06:07 +02:00
Stjepan Glavina 272bb11eaf Add feature 2020-09-20 17:45:24 +02:00
Jayce Fayne 2ecb5564e8 remove `libc` dependency on windows 2020-09-16 11:23:03 +02:00
oblique f7f67e8745 Fix linkage error for android-16 toolchain 2020-09-15 14:01:09 +03:00
oblique 62103c1ef0 Check if `epoll_create1` is implemented by its error code
If binary is statically linked to libc then `libc::dlsym`
will always return `NULL`. This is the case when a target
with musl is used.

To fix this we check if error code of `epoll_create1` is `ENOSYS`.
2020-09-15 14:01:09 +03:00
Stjepan Glavina 4fc3040bff Pass timeout in ms to epoll_wait 2020-09-14 21:06:16 +02:00
Stjepan Glavina 7738ca0b25 Remove doc-comment because the readme then needs the ugly #-prefixed line 2020-09-07 19:53:31 +02:00
Dan Gohman d22ed8fd7b Fix compilation on x32
Fix compilation on x86_64-unknown-linux-gnux32, where
libc's timespec's `tv_nsec` is [defined as `i64`]. See also
[this bug] bug for further discussion.

[defined as `i64`]: https://github.com/rust-lang/libc/blob/master/src/unix/mod.rs#L61
[this bug]: https://sourceware.org/bugzilla/show_bug.cgi?id=16437
2020-09-05 22:17:26 -07:00
Stjepan Glavina bc3dc1ec6e Replace log::debug with log::trace 2020-09-03 12:55:46 +02:00
Stjepan Glavina 91bf9a4cf6 Fix compilation error 2020-09-01 06:49:20 +02:00
Stjepan Glavina 4b4b774116 Cleanup 2020-09-01 06:48:09 +02:00
Stjepan Glavina 3fdcd68e23 Specify oneshot when inserting into epoll/wepoll 2020-09-01 06:42:08 +02:00
Stjepan Glavina d106cef8c4 Bump to v0.1.6 2020-08-29 17:34:45 +02:00
Stjepan Glavina 654ddca8a6 Add logging 2020-08-29 16:07:51 +02:00
Stjepan Glavina 8f1c4e530d Set timeout to 0 when non-blocking epoll_wait 2020-08-15 09:05:58 +02:00
Stjepan Glavina 94b263817d Add missing import 2020-08-15 08:45:10 +02:00
Stjepan Glavina e5a8b08578 Use timeout_ms again 2020-08-15 08:40:12 +02:00
Stjepan Glavina 7a1d7386ba Set interest after configuring timerfd 2020-08-15 08:31:00 +02:00
Stjepan Glavina d183433d9e Add timeout test 2020-08-15 08:14:52 +02:00
Stjepan Glavina a7bae2f5c4 Return from wait if there was a notification 2020-08-14 16:33:28 +02:00
Stjepan Glavina 3364fabe0e Fix a comment 2020-08-14 16:08:59 +02:00
Stjepan Glavina f9fb1849e3 Small fixes 2020-08-14 16:08:13 +02:00
Stjepan Glavina 3f721e5498 Add notified flag 2020-08-14 16:07:53 +02:00
Stjepan Glavina d13ddbe0ff Fix timeout calculation on windows 2020-08-14 16:02:30 +02:00
Stjepan Glavina 9d9b8361e5 Fix compilation errors 2020-08-14 15:26:54 +02:00
Stjepan Glavina f1f3d4609c Another try on windows 2020-08-14 15:18:44 +02:00
Stjepan Glavina d645f95ecb Fix compilation errors 2020-08-14 14:59:24 +02:00
Stjepan Glavina 992ee10ee7 Round up to a whole millisecond 2020-08-14 14:47:32 +02:00
Stjepan Glavina db4e8d7dec Typo 2020-08-14 14:39:13 +02:00
Stjepan Glavina 11f77ff54b Some polish 2020-08-14 14:38:02 +02:00
Stjepan Glavina c6818f038f Sub-nanosecond precision for epoll 2020-08-14 13:46:58 +02:00
Stjepan Glavina 4a1a2d673a Fix a comment 2020-08-14 12:55:23 +02:00
Stjepan Glavina eb1f0872ef
Merge pull request #1 from GuillaumeGomez/doc-comment
Add doc-comment to test README's examples
2020-08-13 20:58:13 +02:00
Mike Zeller c128438ffb Add error handling around event ports fcntl 2020-08-11 15:52:57 +00:00
Stjepan Glavina 30ca45f83f
Merge pull request #3 from papertigers/illumos
Add event ports for illumos
2020-08-11 13:15:36 +02:00
Mike Zeller 2d292a86c3 Some more cleanup 2020-08-10 17:16:06 +00:00
Stjepan Glavina cf5971da09 Docs 2020-08-08 10:20:19 +02:00
Stjepan Glavina 08745b5c50 Document non-blocking mode 2020-08-08 10:20:19 +02:00
Mike Zeller 59a4e6b150 Fix left over mentions of epoll 2020-08-06 20:53:33 +00:00
Mike Zeller a17f28d26c Add event ports for illumos 2020-08-06 20:42:44 +00:00
rrokkam 8e3a332b90 Event::none creates an event that is not readable or writable 2020-08-06 09:03:28 -07:00
Guillaume Gomez 8d77ab712f Add doc-comment to test README's examples 2020-08-06 16:12:52 +02:00
Stjepan Glavina d763bb2d90 Fix compilation errors 2020-08-06 15:10:39 +02:00
Stjepan Glavina 5b32dd8e82 Initial commit 2020-08-06 15:05:24 +02:00