-
Notifications
You must be signed in to change notification settings - Fork 809
Description
Currently mio exposes two sets of APIs for dealing with network operations:
- The high-level TCP, UDP & UDS interface
- The very low-level and platform-specific Unix fd polling and windows handle registration interfaces
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 also unsafe 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:
- Connecting a socket:
connect(ConnectExon Windows) - Reading data from socket:
recv,recvfrom,recvmsg(WSARecv*on Windows) - Writing data to socket:
send,sendto,sendmsg(WSASend*on Windows) - Accepting new client connections:
accept(AcceptExon 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 implement mio::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 as recv/send (what TCP currently does), recvfrom/sendto (like UDP) and possibly even connect/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" for mio 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)?