You're on the right track! I'm assuming that you're working with serial as a custom file descriptor, and you're wondering how to get that custom file descriptor (set to async mode) hooked up to futures and everything. To do that, you'd follow steps that look like:
- Verify your file descriptor works with
epoll
(assuming you're on Linux) - Create a type and implement
Evented
for it. This will likely useEventedFd
internally, probably like so. Remember that if you're passing ownership of the file descriptor to this type implementingEvented
that you'll want to implement a destructor that closes it. - When working with
tokio-core
, you'll want to then pass this type that implementsEvented
to thePollEvented
type. This is what hooks up your file descriptor to the tokio-core event loop. - If you interact with the file descriptor via
read
andwrite
then you're done! TheRead
andWrite
trait implementations onPollEvented
are all you'll need. - If you need functionality other than
read
andwrite
, then you'll need to implement your own methods that callpoll_read
,poll_write
,need_read
, andneed_write
manually (all methods onPollEvented
). You can see an example of this inUdpSocket::recv_from
.
Hope that helps!