-
Notifications
You must be signed in to change notification settings - Fork 744
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
[IDEA] Expose low-level socket operations #550
Comments
Just so you know I may actually implement this so it would be very useful to know whether it makes more sense to attempt to implement this on top of or in mio itself. Therefor I'd be very interested to hear your thoughts about this. |
I think what you are describing existed in a rougher form in past versions of Mio. Specifically Io which is currently private. I think what you are describing is useful, but I am not sure if it is something that should be made public. The goal right now is to provide a compatibility layer to the OS's polling platform. TCP / UDP are also provided because they are so common, but I would like to limit additions as much as possible, especially if they can live in third party crates (in part so that I have less to maintain :)). You should definitely give it a shot in a separate crate and we can evaluate if it makes sense to include after that. |
I'm going to close the issue for now. If you have more to discuss, you can continue here or open a new issue. Cheers. |
Thanks for your response! (Including the link to the private That turned out way too long, so here's the TL;DR:
Since my opening post I've put some more thought into how it would make sense to implement this in the context of My attempt at designing an the public-facing API for the
It seems however that (2) and (3) are actually less of a requirement than it might seem at at first, because their implementation in My conclusion from this is that the main problem in supporting other socket types lies not so much in Is there any API of non-Inet sockets in |
Sounds like you are making some progress. I am not really following everything, but as long as you can, I would try to experiment in a standalone crate. If you hit issues that prevent you from doing so (that require mio changes), open a new issue. Cheers. |
Well, my idea would basically be to generalize the current TCP and UDP specific code to work for arbitrary stream and datagram sockets. This is a change much more in name and in the documented guarantees than in actual code. The main problem with this is that it would result in some, IMHO needless, duplication of code from
Thanks for your consideration! |
At this point, I would rather not extend the API surface. More API surface means more code to maintain :-) |
Currently
mio
exposes two sets of APIs for dealing with network operations:However for many operations (such as maintaining a Bluetooth RFCOMM/SPP connection or talking the the kernel using netlink) that will never be part of
mio
core, currently the only option is to go "really low-level", and alsounsafe
on Windows, to implement these things. (Please, by all means, correct me if I'm wrong!)In particular the following operations are asynchronously implementable in a safe and cross-platform way for any socket type:
connect
(ConnectEx
on Windows)recv
,recvfrom
,recvmsg
(WSARecv*
on Windows)send
,sendto
,sendmsg
(WSASend*
on Windows)accept
(AcceptEx
on Windows)Looking a
mio
's current architecture implementing this would probably take the form of a bunch of new structs that take a socket fd/handle and each implementmio::Evented
allowing them to be polled as usual, becoming ready when they have something to return. This whole process also happens to be at the essence of the TCP and UDP implementations already do internally anyways. The API can also easily be designed in a way that preserves the meaning of the interest bits by grouping together related operations, such asrecv
/send
(what TCP currently does),recvfrom
/sendto
(like UDP) and possibly evenconnect
/accept
(as sockets become writable when they are fully connected and become "readable" when they have new incoming clients). Layering the current TCP/UDP/UDS on top of such an interface (or maybe even moving them to another crate because they are "too high-level" formio
core itself) would be quite trivial and would allow other, lesser-used protocols, to reuse the same facilities.Do you agree that this is something that
mio
core should support (if patches, … are provided)?The text was updated successfully, but these errors were encountered: