Commit Graph

60 Commits

Author SHA1 Message Date
Nikolay Arhipov 9e46c8455c
feat: ported to Vita target
Fixes #160
2024-04-20 11:22:46 -07:00
irvingouj @ Devolutions e25b3b4e4c
feat: Replace is_connect_failed with is_err
In linux, epoll, EPOLLHUP may happen even if no connection call is made. It
would confuse callers for what is actually happening.

Replaced is_connect_failed, and we detect if connection failed by using the
combination of is_err and is_interrupt, please see the example, tcp_client
2024-03-20 22:04:46 -07:00
John Nunley 50454d1cea
feat: Add support for HermitOS
HermitOS is a microkernel target aiming to provide a simple OS for
virtualized applications. It recently added support for the poll() and
eventfd() system calls, which means we can target it with our poll()
based backend.

Hermit does not have a traditional libc; instead it uses hermit-abi.
However rustix does not support using hermit-abi as its underlying
layer yet. So we have to build a shim layer until it does.

Closes #177
cc bytecodealliance/rustix#1012

Signed-off-by: John Nunley <dev@notgull.net>
2024-03-12 21:33:06 -07:00
John Nunley 77b4ed1156
feat: On RedoxOS, use epoll instead of the poll backend
Technically RedoxOS supports the poll syscall, so we already support
RedoxOS. However, this is very slow. This commit ports this code to
epoll, which should be more efficient.

Closes #176
2024-02-11 08:31:13 -08:00
irvingouj @ Devolutions cf25dd85f8
feat: Add the ability to identify if the connection has failed 2024-01-26 12:58:39 -08:00
John Nunley b9ab821df1
bugfix: Handle interrupts while polling
Previous, `Poller::wait` would bubble signal interruption error to the user.
However, this may be unexpected for simple use cases. Thus, this commit makes
it so, if `ErrorKind::Interrupted` is received by the underlying `wait()` call,
it clears the events and tries to wait again.

This also adds a test for this interruption written by @psychon.

Co-Authored-By: Uli Schlachter <psychon@users.noreply.github.com>
Signed-off-by: John Nunley <dev@notgull.net>
2023-10-27 07:02:08 -07:00
Uli Schlachter 0575cbd4bc
docs: Fix wrong link in docs of Poller::wait()
Once upon a time, this got a Vec as an argument, but that was replaced
with the Events struct. Thus, this should link to Events and not Vec.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-10-20 09:49:44 -07:00
tison ceb88a46c4
chore: prefer usize::MAX to std::usize::MAX
Signed-off-by: tison <wander4096@gmail.com>
2023-10-05 20:10:18 -07:00
David Hotham 254577da8d
feat: introduce Event::new()
This makes it easier to construct Events.
2023-09-12 06:02:02 -07:00
John Nunley 90c661f5e1 Remove the std default feature
Added in 272bb11eaf for reasons that are
unclear to me. It serves no purpose aside from disabling the API of the
entire crate, so it's best to remove it.

Signed-off-by: John Nunley <dev@notgull.net>
2023-09-04 22:15:28 +02:00
tison d8595b56a5
feat: Make the constructors for Event const
This allows the Event struct to be used in constants.

Signed-off-by: tison <wander4096@gmail.com>
2023-08-21 18:32:21 -07:00
John Nunley c7cc91a1f1
docs: Specify behavior when registered in multiple pollers
This adds documentation to add() describing what happens when a source
is registered in multiple pollers. A test is also added to ensure this
behavior.

Signed-off-by: John Nunley <dev@notgull.net>
2023-08-16 09:48:14 -07:00
John Nunley a521cd2c29
breaking: Extract the Events struct and make the Event struct opaque
* Add better documentation for the IOCP module

* Extract Events from Poller

This prevents the need to have an intermediate buffer to read events
from, reducing the need for an allocation and a copy. This is a breaking
change.

* Add event extra information

Foundation for more details later on.

* Add PRI and HUP events
* Fix various failing tests

- Make sure that waitable handles interact properly with the new
  infrastructure
- Fix failing doctests

* Review comments

- Make set_* take a boolean for the value of the flag
- Make Events !Sync
- Fix visibility modifiers
- Inline more methods
- Use a better strategy for testing

* Move completion packets into the Events buffer

This removes one of the mutexes that we have to lock.

* Review comments

Signed-off-by: John Nunley <dev@notgull.net>
2023-08-14 10:03:20 -07:00
John Nunley 6eb7679aa3
breaking: Rework the API for I/O safety
* Rework the API for I/O safety

* Bump to rustix v0.38
2023-08-03 20:15:59 -07:00
John Nunley c86c3894c1
Add smol-rs logo (#127) 2023-07-17 14:30:22 +09:00
John Nunley 7a1fd31944
Replace log with tracing (#119) 2023-06-20 20:28:18 -07:00
John Nunley 5df378f811
Bump MSRV to 1.63 (#117)
Removes the build script and bumps bitflags to v2
2023-06-11 10:37:25 -07:00
John Nunley 8d8d2efcc2
Replace libc with rustix in some backends (#108) 2023-04-23 07:26:29 -07:00
John Nunley 0f38ed35ea
Add edge/oneshot combination mode (#96) 2023-03-25 15:22:45 +01:00
John Nunley 24900fb662
m(windows): Reimplement Wepoll in Rust (#88)
Reimplements the C-based wepoll backend in Rust, using some handwritten code. This PR also implements bindings to the I/O Completion Ports and \Device\Afd APIs. For more information on the latter, see my blog post on the subject: https://notgull.github.io/device-afd/

Note that the IOCP API is wrapped using a `Pin`-oriented "CompletionHandle" system that is relatively brittle. This should be replaced with a better model when one becomes available.
2023-03-05 16:25:25 -08:00
John Nunley a5aae98805
feat: Expose other kqueue filters (#83)
* feat: Expose other kqueue filters

* Fix netbsd/openbsd compilation

* Build MSRV for FreeBsd/OpenBsd in CI

* Only run MSRV BSD builds on Linux

* Change API a little + fix netbsd timer

* Add inlines + move PollerSealed

* rustfmt

* Make filter fields public

* Fix examples
2023-02-03 11:14:33 -08:00
John Nunley 181acc67d0
Add level and edge triggered modes to the poller (#59)
* Add level and edge triggered modes to the poller

* Refractor error handling

* Add tests for new modes
2022-12-30 14:43:47 -08:00
Taiki Endo bc56d1fb38
Test the backend that uses poll on CI (#63) 2022-12-29 16:01:25 +09:00
Taiki Endo 5e9bedbae8 Sort target_os cfg to match docs 2022-12-28 12:24:56 +09:00
John Nunley 97e6ecd0d0
Support tvOS and watchOS (#60) 2022-12-19 19:54:45 -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 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
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
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 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
Stjepan Glavina f4ee76fb32 Bump to v2.0.1 2020-10-09 14:10:22 +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
Stjepan Glavina 7738ca0b25 Remove doc-comment because the readme then needs the ugly #-prefixed line 2020-09-07 19:53:31 +02:00
Stjepan Glavina bc3dc1ec6e Replace log::debug with log::trace 2020-09-03 12:55:46 +02:00
Stjepan Glavina 4b4b774116 Cleanup 2020-09-01 06:48:09 +02:00
Stjepan Glavina 654ddca8a6 Add logging 2020-08-29 16:07:51 +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 c6818f038f Sub-nanosecond precision for epoll 2020-08-14 13:46:58 +02:00