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

Remove net2 dependency #1029

Merged
merged 24 commits into from Aug 13, 2019
Merged

Remove net2 dependency #1029

merged 24 commits into from Aug 13, 2019

Conversation

Thomasdezeeuw
Copy link
Collaborator

@Thomasdezeeuw Thomasdezeeuw commented Jul 11, 2019

This initial comment only remove net2 from TcpStream::connect, on Unix platforms (expect for iOS, macOS and Solaris) this reduces the number of system calls from three to two.

@carllerche this does increase the complexity a bit, do we still want to continue down this route?

Closes #841.
Closes #1045.

src/sys/unix/tcp.rs Outdated Show resolved Hide resolved
Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me. One thought re copyright.

@Thomasdezeeuw
Copy link
Collaborator Author

Note to self: check for the same problem as in #1031 in the changes I'm going to make.

@carllerche
Copy link
Member

We should be fine to move forward w/ this if you want to.

@Thomasdezeeuw
Copy link
Collaborator Author

@carllerche I was thinking about waiting until the Windows rewrite as I imagine there will a number of merge conflicts. But I'll finish this.

@Thomasdezeeuw
Copy link
Collaborator Author

I've force pushed a commit. It is rebased on master and contains the code for Windows as well, still limited to TcpStream::connect.

})
.and_then(|socket| {
// Required for a future `connect_overlapped` operation to be
// executed successfully.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the rewrite does this still apply?

@Thomasdezeeuw
Copy link
Collaborator Author

After some trial and error this now works on Windows. Can some double check the code since I just developed it of the documentation and didn't run anything locally.

@Thomasdezeeuw
Copy link
Collaborator Author

I'm getting the Either the application has not called WSAStartup, or WSAStartup failed. error on Windows, can someone with some Windows knowledge help me with that?

@carllerche
Copy link
Member

cc @piscisaureus @PerfectLaugh ^^

We probably are missing a run_once call to WSAStartup?

@PerfectLaugh
Copy link
Contributor

PerfectLaugh commented Jul 21, 2019 via email

@PerfectLaugh
Copy link
Contributor

PerfectLaugh commented Jul 21, 2019 via email

@carllerche
Copy link
Member

@PerfectLaugh How can we ensure it gets called?

@carllerche
Copy link
Member

@Thomasdezeeuw In case you didn't know, you can run cargo check --target x86_64-pc-windows-msvc while not on windows to at least make sure things will compile.

@PerfectLaugh
Copy link
Contributor

PerfectLaugh commented Jul 21, 2019 via email

@Thomasdezeeuw
Copy link
Collaborator Author

@Thomasdezeeuw In case you didn't know, you can run cargo check --target x86_64-pc-windows-msvc while not on windows to at least make sure things will compile.

I know, but I used build which doesn't check tests (I just found out) :).

@carllerche
Copy link
Member

@PerfectLaugh it looks like init() is only called when using a TCP or UDP type, so it is possible for us to hit cases where we need WSAStartup() called.

@Thomasdezeeuw
Copy link
Collaborator Author

Seems that we need basically a function in std::net for init to be called.

@Thomasdezeeuw
Copy link
Collaborator Author

Oh TcpStream and TcpListener don't implement to/as/from_raw_socket, want me to add that? Since I've already used it in a test.

@PerfectLaugh
Copy link
Contributor

PerfectLaugh commented Jul 21, 2019 via email

@PerfectLaugh
Copy link
Contributor

PerfectLaugh commented Jul 21, 2019 via email

@Thomasdezeeuw
Copy link
Collaborator Author

I've disabled connection_reset_by_peer for now as it requires net2.

@carllerche
Copy link
Member

@Thomasdezeeuw it seems ok to maintain a dev-dependency on net2.

@Thomasdezeeuw
Copy link
Collaborator Author

I've added a dummy listener to test_close_on_drop as a workaround and opened #1046.

@Thomasdezeeuw
Copy link
Collaborator Author

So I've an init function to the tests that will create a TcpListener (from standard library) to trigger it to call WSAStartup, so the tests run fine now. However now the same problem occurs in the examples. I think we need to resolve #1046 before this can be merged.

The standard library calls WSAStartup for us, ensuring (with an assert)
that the return value is ok. This means that we can't initialise it
ourselves and need to let the standard library do it for us. To work
around this we create and drop a UdpSocket (from std::net).
This is now handled inside the crate.
@Thomasdezeeuw Thomasdezeeuw marked this pull request as ready for review August 3, 2019 17:01
@Thomasdezeeuw
Copy link
Collaborator Author

I've added an init function to Windows' TCP types, matching what libstd does. I think this pr is ready, I haven't gotten around to UdpSocket but I want to get this merged to prevent further delays (and merge conflicts).

@Thomasdezeeuw
Copy link
Collaborator Author

@PerfectLaugh I can't request your review, but can you look at the Windows implementation?

@PerfectLaugh
Copy link
Contributor

Looks good to me and have no issue of test in my computer.
Btw. You should look my pull request and try to make changes into your commit. #1042 so I can close my pull request then :)

@Thomasdezeeuw
Copy link
Collaborator Author

@asomers, @carllerche any chance you have some time to review this?

Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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.

Reduce TcpStream, TcpListener and UdpSocket API to the same as in libstd Switch from net2 to socket2
3 participants