Function multistream_select::listener_select_proto
source · pub fn listener_select_proto<R, I, X>(
inner: R,
protocols: I
) -> ListenerSelectFuture<R, I, X>where
R: AsyncRead + AsyncWrite,
for<'r> &'r I: IntoIterator<Item = X>,
X: AsRef<[u8]>,
Expand description
Helps selecting a protocol amongst the ones supported.
This function expects a socket and an iterator of the list of supported protocols. The iterator must be clonable (i.e. iterable multiple times), because the list may need to be accessed multiple times.
The iterator must produce tuples of the name of the protocol that is advertised to the remote,
a function that will check whether a remote protocol matches ours, and an identifier for the
protocol of type P
(you decide what P
is). The parameters of the function are the name
proposed by the remote, and the protocol name that we passed (so that you don’t have to clone
the name).
On success, returns the socket and the identifier of the chosen protocol (of type P
). The
socket now uses this protocol.