Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport switch to winapi 0.3 onto mio 0.6 #1629

Closed
wants to merge 1 commit into from

Conversation

RalfJung
Copy link

@RalfJung RalfJung commented Nov 12, 2022

Needed for this to still build after rust-lang/rust#102513.
Cc @Thomasdezeeuw @Noah-Kennedy

This is a direct port of 756bf28.
I have zero familiarity with mio, winapi, and the Windows APIs... so I hope this makes sense.^^ I don't even have a Windows machine to build-test this; I used cargo miri since that is able to do check-builds for foreign targets.

@RalfJung RalfJung changed the title backport switch to winapi 0.3 backport switch to winapi 0.3 onti mio 0.6 Nov 12, 2022
@RalfJung RalfJung changed the title backport switch to winapi 0.3 onti mio 0.6 backport switch to winapi 0.3 onto mio 0.6 Nov 12, 2022
@Thomasdezeeuw
Copy link
Collaborator

The entire CI for v0.6 is too old to run, all the images are no longer available. So either we need to port the CI to something that works or someone with a Window machine needs to manually test this.

@Nilstrieb
Copy link

I've tested (cargo test --all-features) the code manually on my Windows 11 machine (with --cap-lints=warn because of all the deny-by-default UB lints :D) and all tests pass.

Output
PS C:\Users\nilsh\mio> cargo test --all-features
warning: this `#[deprecated]` annotation has no effect
   --> src\event_imp.rs:515:1
    |
515 | #[deprecated(since = "0.6.10", note = "removed")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute
    |
    = note: `#[warn(useless_deprecated)]` on by default

warning: this `#[deprecated]` annotation has no effect
    --> src\event_imp.rs:1002:1
     |
1002 | #[deprecated(since = "0.6.10", note = "removed")]
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute

warning: an associated function with this name may be added to the standard library in the future
   --> src\sys\windows\tcp.rs:192:31
    |
192 |         self.imp.inner.socket.set_linger(dur)
    |                               ^^^^^^^^^^
    |
    = note: `#[warn(unstable_name_collisions)]` on by default
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
    = help: call with fully qualified syntax `net2::TcpStreamExt::set_linger(...)` to keep using the current method

warning: an associated function with this name may be added to the standard library in the future
   --> src\sys\windows\tcp.rs:196:31
    |
196 |         self.imp.inner.socket.linger()
    |                               ^^^^^^
    |
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
    = help: call with fully qualified syntax `net2::TcpStreamExt::linger(...)` to keep using the current method

warning: dereferencing a null pointer
   --> src\sys\windows\selector.rs:474:10
    |
474 |         &(*(0 as *const $t)).$($field).+ as *const _ as usize
    |          ^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
    |
   ::: src\sys\windows\tcp.rs:529:25
    |
529 |         inner: unsafe { overlapped2arc!(status.overlapped(), StreamIo, read) },
    |                         ---------------------------------------------------- in this macro invocation
    |
    = note: `#[warn(deref_nullptr)]` on by default
    = note: this warning originates in the macro `offset_of` which comes from the expansion of the macro `overlapped2arc` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: dereferencing a null pointer
   --> src\sys\windows\selector.rs:474:10
    |
474 |         &(*(0 as *const $t)).$($field).+ as *const _ as usize
    |          ^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
    |
   ::: src\sys\windows\tcp.rs:567:25
    |
567 |         inner: unsafe { overlapped2arc!(status.overlapped(), StreamIo, write) },
    |                         ----------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `offset_of` which comes from the expansion of the macro `overlapped2arc` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: dereferencing a null pointer
   --> src\sys\windows\selector.rs:474:10
    |
474 |         &(*(0 as *const $t)).$($field).+ as *const _ as usize
    |          ^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
    |
   ::: src\sys\windows\tcp.rs:780:25
    |
780 |         inner: unsafe { overlapped2arc!(status.overlapped(), ListenerIo, accept) },
    |                         -------------------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `offset_of` which comes from the expansion of the macro `overlapped2arc` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: dereferencing a null pointer
   --> src\sys\windows\selector.rs:474:10
    |
474 |         &(*(0 as *const $t)).$($field).+ as *const _ as usize
    |          ^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
    |
   ::: src\sys\windows\udp.rs:391:25
    |
391 |         inner: unsafe { overlapped2arc!(status.overlapped(), Io, write) },
    |                         ----------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `offset_of` which comes from the expansion of the macro `overlapped2arc` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: dereferencing a null pointer
   --> src\sys\windows\selector.rs:474:10
    |
474 |         &(*(0 as *const $t)).$($field).+ as *const _ as usize
    |          ^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
    |
   ::: src\sys\windows\udp.rs:402:25
    |
402 |         inner: unsafe { overlapped2arc!(status.overlapped(), Io, read) },
    |                         ---------------------------------------------- in this macro invocation
    |
    = note: this warning originates in the macro `offset_of` which comes from the expansion of the macro `overlapped2arc` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: `mio` (lib) generated 9 warnings
warning: unused macro definition: `assert_not_ready`
  --> test\test_tcp_shutdown.rs:78:14
   |
78 | macro_rules! assert_not_ready {
   |              ^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_macros)]` on by default

warning: unused import: `iovec::IoVec`
 --> test\test_udp_socket.rs:8:5
  |
8 | use iovec::IoVec;
  |     ^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: an associated function with this name may be added to the standard library in the future
   --> test\test_tcp.rs:513:12
    |
513 |     client.set_linger(Some(Duration::from_millis(0))).unwrap();
    |            ^^^^^^^^^^
    |
    = note: `#[warn(unstable_name_collisions)]` on by default
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
    = help: call with fully qualified syntax `net2::TcpStreamExt::set_linger(...)` to keep using the current method

warning: an associated function with this name may be added to the standard library in the future
   --> test\test_tcp_shutdown.rs:238:23
    |
238 |     assert_ok!(socket.set_linger(Some(Duration::from_millis(0))));
    |                       ^^^^^^^^^^
    |
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
    = help: call with fully qualified syntax `net2::TcpStreamExt::set_linger(...)` to keep using the current method

warning: an associated function with this name may be added to the standard library in the future
   --> src\sys\windows\tcp.rs:192:31
    |
192 |         self.imp.inner.socket.set_linger(dur)
    |                               ^^^^^^^^^^
    |
note: the lint level is defined here
   --> src\lib.rs:6:24
    |
6   | #![cfg_attr(test, deny(warnings))]
    |                        ^^^^^^^^
    = note: `#[warn(unstable_name_collisions)]` implied by `#[warn(warnings)]`
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
    = help: call with fully qualified syntax `net2::TcpStreamExt::set_linger(...)` to keep using the current method

warning: dereferencing a null pointer
   --> src\sys\windows\selector.rs:474:10
    |
474 |         &(*(0 as *const $t)).$($field).+ as *const _ as usize
    |          ^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
    |
   ::: src\sys\windows\tcp.rs:529:25
    |
529 |         inner: unsafe { overlapped2arc!(status.overlapped(), StreamIo, read) },
    |                         ---------------------------------------------------- in this macro invocation
    |
    = note: `#[warn(deref_nullptr)]` implied by `#[warn(warnings)]`
    = note: this warning originates in the macro `offset_of` which comes from the expansion of the macro `overlapped2arc` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: `mio` (test "test") generated 4 warnings
warning: `mio` (lib test) generated 9 warnings (7 duplicates)
    Finished test [unoptimized + debuginfo] target(s) in 0.12s
     Running unittests src\lib.rs (target\debug\deps\mio-d5b23a598c4cc5f7.exe)

running 29 tests
test event_imp::test_debug_pollopt ... ok
test lazycell::tests::atomic_replace ... ok
test event_imp::test_debug_ready ... ok
test lazycell::tests::normal_replace ... ok
test lazycell::tests::test_already_filled_error ... ok
test lazycell::tests::test_atomic_already_filled_panic ... ok
test lazycell::tests::test_borrow_mut ... ok
test lazycell::tests::test_atomic_fill_and_borrow ... ok
test lazycell::tests::test_atomic_into_inner ... ok
test lazycell::tests::test_borrow_with_already_filled ... ok
test lazycell::tests::test_borrow_with_not_called_when_filled ... ok
test lazycell::tests::test_atomic_borrow_from_empty ... ok
test lazycell::tests::test_borrow_mut_with ... ok
test lazycell::tests::test_try_borrow_mut_with_already_filled ... ok
test lazycell::tests::test_try_borrow_mut_with_err ... ok
test lazycell::tests::test_borrow_mut_with_not_called_when_filled ... ok
test lazycell::tests::test_borrow_with ... ok
test lazycell::tests::test_try_borrow_with_ok ... ok
test lazycell::tests::test_try_borrow_with_sound_with_reentrancy - should panic ... ok
test lazycell::tests::test_borrow_with_sound_with_reentrancy - should panic ... ok
test lazycell::tests::test_fill_and_borrow ... ok
test lazycell::tests::test_into_inner ... ok
test lazycell::tests::test_borrow_mut_with_already_filled ... ok
test lazycell::tests::test_try_borrow_mut_with_ok ... ok
test lazycell::tests::test_try_borrow_with_err ... ok
test lazycell::tests::test_borrow_from_empty ... ok
test sys::windows::from_raw_arc::tests::drops ... ok
test sys::windows::from_raw_arc::tests::smoke ... ok
test lazycell::tests::test_try_borrow_with_already_filled ... ok

test result: ok. 29 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s

     Running test/mod.rs (target\debug\deps\test-f85f38daa85740c1.exe)

running 58 tests
test test_custom_evented::smoke ... ok
test test_poll_channel::test_dropping_receive_before_poll ... ok
test test_notify::test_notify_capacity ... ok
test test_register_multiple_event_loops::test_udp_register_multiple_event_loops ... ok
test test_multicast::test_multicast ... ok
test test_double_register::test_double_register ... ok
test test_oneshot::test_tcp_edge_oneshot ... ok
test test_register_deregister::test_register_empty_interest ... ok
test test_register_multiple_event_loops::test_tcp_register_multiple_event_loops ... ok
test test_smoke::add_then_drop ... ok
test test_tcp::bind_twice_bad ... ok
test test_tcp::connect_then_close ... ok
test test_register_deregister::test_register_deregister ... ok
test test_local_addr_ready::local_addr_ready ... ok
test test_echo_server::test_echo_server ... ok
test test_tcp::accept ... ok
test test_close_on_drop::test_close_on_drop ... ok
test test_tcp::connect ... ok
test test_tcp::listen_then_close ... ok
test test_tcp::test_tcp_sockets_are_send ... ok
test test_tcp::multiple_writes_immediate_success ... ok
test test_tcp::write_error ... ok
test test_tcp_level::test_tcp_listener_level_triggered ... ok
test test_poll::test_poll_closes_fd ... ok
test test_tcp_shutdown::test_abrupt_shutdown ... ok
test test_tcp_shutdown::test_graceful_shutdown ... ok
test test_tcp_shutdown::test_write_shutdown ... ok
test test_udp_socket::test_udp_socket ... ok
test test_custom_evented::stress::with_small_events_collection ... ok
test test_udp_socket::test_udp_socket_discard ... ok
test test_udp_socket::test_udp_socket_send_recv ... ok
test test_write_then_drop::write_then_deregister ... ok
test test_write_then_drop::write_then_drop ... ok
test test_notify::test_notify_drop ... ok
test test_custom_evented::stress::multi_threaded_poll ... ok
test test_smoke::run_once_with_nothing ... ok
test test_tcp::connection_reset_by_peer ... ok
test test_poll_channel::test_mixing_channel_with_socket ... ok
test test_tick::test_tick ... ok
test test_tcp::peek ... ok
test test_custom_evented::drop_registration_from_non_main_thread ... ok
test test_tcp::read ... ok
test test_poll_channel::test_poll_channel_level ... ok
test test_tcp::write ... ok
test test_udp_level::test_udp_level_triggered ... ok
test test_poll_channel::test_poll_channel_writable ... ok
test test_tcp_level::test_tcp_stream_level_triggered ... ok
test test_custom_evented::set_readiness_before_register ... ok
test test_poll_channel::test_poll_channel_edge ... ok
test test_tcp::write_bufs ... ok
test test_notify::test_notify ... ok
test test_reregister_without_poll::test_reregister_different_without_poll ... ok
test test_poll_channel::test_sending_from_other_thread_while_polling ... ok
test test_tcp::read_bufs ... ok
test test_battery::test_echo_server ... ok
test test_poll_channel::test_poll_channel_oneshot ... ok
test test_custom_evented::stress::single_threaded_poll ... ok
test test_tcp::connect_error ... ok

test result: ok. 58 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.02s

   Doc-tests mio

running 68 tests
test src\event_imp.rs - event_imp::PollOpt::contains (line 415) ... ok
test src\event_imp.rs - event_imp::PollOpt::edge (line 249) ... ok
test src\event_imp.rs - event_imp::PollOpt::is_oneshot (line 365) ... ok
test src\event_imp.rs - event_imp::PollOpt::empty (line 229) ... ok
test src\event_imp.rs - event_imp::Event::readiness (line 1101) ... ok
test src\event_imp.rs - event_imp::PollOpt::contains (line 406) ... ok
test src\event_imp.rs - event_imp::PollOpt::contains (line 424) ... ok
test src\event_imp.rs - event_imp::PollOpt (line 208) ... ok
test src\event_imp.rs - event_imp::Event (line 1056) ... ok
test src\event_imp.rs - event_imp::Ready::all (line 694) ... ok
test src\event_imp.rs - event_imp::PollOpt::oneshot (line 289) ... ok
test src\event_imp.rs - event_imp::PollOpt::level (line 269) ... ok
test src\event_imp.rs - event_imp::Event::new (line 1081) ... ok
test src\event_imp.rs - event_imp::Event::token (line 1124) ... ok
test src\event_imp.rs - event_imp::PollOpt::is_edge (line 325) ... ok
test src\event_imp.rs - event_imp::PollOpt::remove (line 465) ... ok
test src\event_imp.rs - event_imp::PollOpt::is_level (line 345) ... ok
test src\event_imp.rs - event_imp::PollOpt::insert (line 446) ... ok
test src\event_imp.rs - event_imp::Evented (line 67) ... ok
test src\event_imp.rs - event_imp::Evented (line 32) ... ok
test src\event_imp.rs - event_imp::Ready (line 579) ... ok
test src\event_imp.rs - event_imp::Ready::empty (line 609) ... ok
test src\event_imp.rs - event_imp::Ready::is_empty (line 715) ... ok
test src\event_imp.rs - event_imp::Ready::readable (line 635) ... ok
test src\event_imp.rs - event_imp::Ready::contains (line 850) ... ok
test src\event_imp.rs - event_imp::Ready::is_readable (line 742) ... ok
test src\event_imp.rs - event_imp::Ready::insert (line 798) ... ok
test src\event_imp.rs - event_imp::Ready::as_usize (line 924) ... ok
test src\event_imp.rs - event_imp::Ready::is_writable (line 762) ... ok
test src\event_imp.rs - event_imp::Ready::contains (line 859) ... ok
test src\event_imp.rs - event_imp::Ready::from_usize (line 899) ... ok
test src\event_imp.rs - event_imp::Ready::contains (line 868) ... ok
test src\event_imp.rs - event_imp::Ready::remove (line 818) ... ok
test src\net\udp.rs - net::udp::UdpSocket::recv_from (line 248) - compile ... ok
test src\net\udp.rs - net::udp::UdpSocket::send_to (line 219) - compile ... ok
test src\event_imp.rs - event_imp::Ready::writable (line 655) ... ok
test src\lib.rs - (line 58) ... ok
test src\net\tcp.rs - net::tcp::TcpStream (line 34) ... ok
test src\net\tcp.rs - net::tcp::TcpListener (line 474) ... ok
test src\net\udp.rs - net::udp::UdpSocket (line 27) ... ok
test src\net\udp.rs - net::udp::UdpSocket::bind (line 102) ... ok
test src\net\udp.rs - net::udp::UdpSocket::local_addr (line 151) ... ok
test src\poll.rs - poll::Events::capacity (line 1380) ... ok
test src\net\udp.rs - net::udp::UdpSocket::broadcast (line 333) ... ok
test src\poll.rs - poll::Events::is_empty (line 1395) ... ok
test src\net\udp.rs - net::udp::UdpSocket::try_clone (line 182) ... ok
test src\net\udp.rs - net::udp::UdpSocket::set_ttl (line 417) ... ok
test src\net\udp.rs - net::udp::UdpSocket::ttl (line 449) ... ok
test src\net\udp.rs - net::udp::UdpSocket::set_broadcast (line 300) ... ok
test src\poll.rs - poll::Events::with_capacity (line 1353) ... ok
test src\poll.rs - poll::Events::iter (line 1410) ... ok
test src\poll.rs - poll::Events (line 1242) ... ok
test src\poll.rs - poll::Events::clear (line 1444) ... ok
test src\poll.rs - poll::Registration (line 375) ... ok
test src\poll.rs - poll::Iter (line 1280) ... ok
test src\poll.rs - poll::Poll (line 90) ... ok
test src\poll.rs - poll::IntoIter (line 1318) ... ok
test src\poll.rs - poll::Poll::poll (line 958) ... ok
test src\poll.rs - poll::SetReadiness::set_readiness (line 1792) ... ok
test src\poll.rs - poll::Poll::deregister (line 877) ... ok
test src\poll.rs - poll::Poll::reregister (line 820) ... ok
test src\poll.rs - poll::Poll::register (line 735) ... ok
test src\poll.rs - poll::SetReadiness::readiness (line 1714) ... ok
test src\poll.rs - poll::SetReadiness::set_readiness (line 1754) ... ok
test src\token.rs - token::Token (line 13) ... ok
test src\poll.rs - poll::Poll::new (line 627) ... ok
test src\poll.rs - poll::Registration::new2 (line 1552) ... ok
test src\poll.rs - poll::Poll (line 267) ... ok

test result: ok. 68 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 3.28s

@RalfJung
Copy link
Author

FWIW @Nilstrieb also came up with a strategy that might let us keep old winapi 0.2 working, so maybe we won't even need this.

@carllerche
Copy link
Member

carllerche commented Nov 14, 2022

0.6 is old, I would not bother updating it. This is especially true because CI is broken, etc.

@RalfJung
Copy link
Author

@carllerche the problem is that the rustc test suite insists on iron remaining buildable. iron depends on mio 0.6. And rust-lang/rust#102513 as-is makes mio 0.6 fail to build.

However rust-lang/rust#104429 hopefully fixes that.

@Thomasdezeeuw
Copy link
Collaborator

@carllerche the problem is that the rustc test suite insists on iron remaining buildable. iron depends on mio 0.6. And rust-lang/rust#102513 as-is makes mio 0.6 fail to build.

If iron is the problem, can't it upgrade to Mio v0.7/v0.8?

@RalfJung
Copy link
Author

Iron depends on mio via tokio, and I am told porting to newer tokio would be a lot of work.

@Noah-Kennedy
Copy link

Noah-Kennedy commented Nov 17, 2022

Iron is built on hyper 0.12 and thus tokio 0.1, and it's also basically unmaintained as far as I am aware.

@Thomasdezeeuw
Copy link
Collaborator

Also look at the Iron commits, the last ones are from late 2019. So, I'm not sure it's worth the effort of maintaining Mio v0.6 any longer if the project depending on it aren't maintained either...

@RalfJung
Copy link
Author

RalfJung commented Nov 17, 2022 via email

@Thomasdezeeuw
Copy link
Collaborator

I'm going to close this since it's it seems no longer needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants