5 releases
0.2.2 | Sep 18, 2023 |
---|---|
0.2.1 | Aug 28, 2023 |
0.2.0 | Aug 28, 2023 |
0.1.1 | Jul 31, 2023 |
0.1.0 | Jul 31, 2023 |
#940 in Asynchronous
313 downloads per month
Used in mini-c-ares-resolver
145KB
3.5K
SLoC
mini-c-ares
A fork of rust-c-ares, which provides
a minimal Rust wrapper for the c-ares
library, for
asynchronous DNS requests.
Most users should likely prefer
c-ares-resolver
, which offers
a much simpler API and more functionality.
Documentation
- API documentation is here.
Contributing
Contributions should be sent to the upstream repo rust-c-ares!
lib.rs
:
A safe wrapper for the c-ares
library.
This crate is a fairly faithful wrapper of c-ares
; which is to say that it preserves some of
the complexity of using the underlying library. If you just want to make a DNS query, you
should probably prefer the c-ares-resolver
crate,
which does the hard work for you.
Direct usage of this crate requires you to pay attention to c-ares
as it tells you which
file descriptors it cares about, and to poll for activity on those file descriptors.
This likely requires you to have an event loop or similar with which to integrate.
Still here? Usage of this crate is as follows:
-
Create a
Channel
. -
Make queries on the
Channel
. Queries all take callbacks, which will be called when the query completes. -
Have
c-ares
tell you what file descriptors to listen on for read and / or write events. You can do this either by providing a callback, which is called whenever the set of interesting file descriptors changes, or by querying theChannel
directly either withget_sock()
or withfds()
. -
Do as
c-ares
asks. That is, listen for the events that it requests, on the file descriptors that it cares about. -
When a file descriptor becomes readable or writable, call either
process_fd()
orprocess()
on theChannel
to tellc-ares
what has happened. -
If you have queries pending and don't see events happening, you still need to call either
process_fd()
orprocess()
at some point anyway - to givec-ares
an opportunity to process any requests that have timed out.
Complete examples showing how to use the library can be found here.
Dependencies
~650KB
~13K SLoC