how can establish() and io() preserve more of lifetime and type for io argument?
mcr opened this issue · 2 comments
I am trying to connect MbedTls to the ureq's newest TLSConnector.
My WIP (does not compile) is at:
https://github.com/AnimaGUS-minerva/ureq/tree/mbedtls-2/examples/mbedtls-req
I pass the desired tcp_stream into establish(), and return a Box that has the dyn ReadWrite trait:
impl TlsConnector for MbedTlsConnector {
fn connect(
&self,
dns_name: &str,
tcp_stream: TcpStream,
) -> Result<Box<dyn ReadWrite>, Error> {
let ctx = self.context.lock().unwrap();
match ctx.establish(tcp_stream, None) {
I need to implement a socket routine for this, returning the same tcp_stream as before, but the obvious method of calling context.io() isn't going to work, because it return dyn Any, and I think that I need a dyn ReadWrite.
impl ReadWrite for MbedTlsConnector {
fn socket(&self) -> Option<&TcpStream> {
let ctx = self.context.lock().unwrap();
Some(&(ctx.io() as TcpStream))
}
}
Looking for advice here. Maybe the wrapper establish()/io() should change?
Or what?
My question remains... I don't know how to get the socket back out, and I think that maybe it is impossible.
ureq would like it so that it can do connection caching. For now, I am just turning that off.
See: algesten/ureq#469