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

Add IoSource #1195

Closed
wants to merge 2 commits into from
Closed

Add IoSource #1195

wants to merge 2 commits into from

Conversation

Thomasdezeeuw
Copy link
Collaborator

@Thomasdezeeuw Thomasdezeeuw commented Dec 7, 2019

IoSource is a wrapper around a raw file descriptor or socket that implements event::Source.

This will replace SourceFd on Unix (not removed in this pr). I'll send some more pr that replace the usage of SourceFd on Unix and use them in the net types on Windows.

Updates #880
Updates #1187

/cc @dtacalau

@Thomasdezeeuw
Copy link
Collaborator Author

#1196 (the last commit) changes TcpStream to use this type, see it for example usage.

@carllerche
Copy link
Member

Thanks for putting this together. I will need to spend more time going through it.

A quick question: if this is public, in what scenarios would a user use this? In my understanding, the AFD strategy only works for types that mio already supports out of the box.

@Thomasdezeeuw
Copy link
Collaborator Author

A quick question: if this is public, in what scenarios would a user use this? In my understanding, the AFD strategy only works for types that mio already supports out of the box.

Correct, but isn't the same true for SourceFd? It depends on the selector what file descriptors are supported.

@carllerche
Copy link
Member

Right... such a refactor is good for internals, but I hesitate to make the type public due to limitations. I think SourceFd is good for Unix and we can document that it is passed through to the selector so see OS docs for limitations. On windows we would need a custom IOCP handler.

Anyway, I will try to make time to review in depth ASAP

@Thomasdezeeuw
Copy link
Collaborator Author

Right... such a refactor is good for internals, but I hesitate to make the type public due to limitations. I think SourceFd is good for Unix and we can document that it is passed through to the selector so see OS docs for limitations. On windows we would need a custom IOCP handler.

Fair. After the first round of reviews I'll make them private and we can see from there if they can be made public.

@dtacalau
Copy link
Contributor

dtacalau commented Dec 7, 2019

With my current understanding of the code I did not see the point of *nix SourceFd, seems like an extra level which can be dropped w/o losing something.

@dtacalau
Copy link
Contributor

dtacalau commented Dec 7, 2019

@Thomasdezeeuw @carllerche Imo we should not do any refactoring, major or minor, of the Windows implementation internals until custom IOCP handlers are implemented (#1047 and #526). Couple of reasons why I think that: current implementation is stable, no known bugs, it has tests supporting it, provides a good base for implementing a new Internal Selector and a new HandlerState. We would be in a better position to refactor having the custom iocp up and running along the Afd stuff. Any refactoring done now could be duplicate work or just code that won't be needed after the custom IOCP handlers. That's why I think this PR, and the now closed PRs #1182 and #1183, would make much sense afterwards.

Let me know what you think.

@Thomasdezeeuw
Copy link
Collaborator Author

With my current understanding of the code I did not see the point of *nix SourceFd, seems like an extra level which can be dropped w/o losing something.

SourceFd is the only way to use Mio with types defined outside of Mio itself. For example I use for mio-pipe and mio-signals.

@Thomasdezeeuw @carllerche Imo we should not do any refactoring, major or minor, of the Windows implementation internals until custom IOCP handlers are implemented (#1047 and #526). Couple of reasons why I think that: current implementation is stable, no known bugs, it has tests supporting it, provides a good base for implementing a new Internal Selector and a new HandlerState. We would be in a better position to refactor having the custom iocp up and running along the Afd stuff. Any refactoring done now could be duplicate work or just code that won't be needed after the custom IOCP handlers. That's why I think this PR, and the now closed PRs #1182 and #1183, would make much sense afterwards.

Let me know what you think.

I strongly disagree with "current implementation is stable, no known bugs", you're one of the people fixing plenty of bugs in the implementation with changes as recent as today. So I wouldn't call it stable or bug free. Furthermore if we get "scared" (for lack of a better word) to change the code it simply means we don't have enough test coverage in my opinion.

If all net types (i.e. UdpSocket, TcpStream and TcpListener) would use IoSource the number of lines (and possible places of bugs) and code duplication in the Windows implementation would be greatly reduced as shown in bb1e93f.

@dtacalau
Copy link
Contributor

dtacalau commented Dec 9, 2019

SourceFd is the only way to use Mio with types defined outside of Mio itself.

@Thomasdezeeuw thanks for explaining usage of SourceFd, I've reviewed the docs, makes more sense now.

As for my other opinion expressed above, "Scared" might not be the proper word, I'd say "cautious" if you want a word to describe it :).

Copy link
Contributor

@kleimkuhler kleimkuhler left a comment

Choose a reason for hiding this comment

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

So this looks really good to me so far. I don't really have any blocker feedback for the logic. It's a little unfortunate Window's selector has so much going on in it, but I that the separation of what IoSourceState is responsible for in {re,de}registering is similar to the net resources.

I'm interested to see how this cleans up other parts of the Windows implementation which I'm assuming a few more changes will be taking place in the PR, but this is a 👍 start to me.

src/io_source.rs Outdated Show resolved Hide resolved
src/io_source.rs Outdated Show resolved Hide resolved
@Thomasdezeeuw
Copy link
Collaborator Author

Postponing until next week, see #1196 (comment).

…ource>

This prevents wrapper types to implement DerefMut and event::Source,
while the inner type also implement event::Source as that will result in
conflicting trait implementations. Perhaps when specialisation is stable
this can be reverted.

This is required to implement DerefMut for IoSource.

Effectively reverts commit 8397102.
IoSource is a wrapper around a raw file descriptor or socket that
implements event::Source.
@Thomasdezeeuw
Copy link
Collaborator Author

Closing in favour of #1236.

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.

4 participants