我正在尝试使用 Rust ws-rs
(基于 mio)建立安全连接。
我认为相关的代码部分:
impl ws::Handler for Client {
fn on_message(&mut self, msg: ws::Message) -> ws::Result<()> {
println!("msg = {}", msg);
self.out.close(ws::CloseCode::Normal)
}
fn upgrade_ssl_client(
&mut self,
sock: TcpStream,
_: &url::Url,
) -> ws::Result<SslStream<TcpStream>> {
let mut builder = SslConnector::builder(SslMethod::tls()).map_err(|e| {
ws::Error::new(
ws::ErrorKind::Internal,
format!("Failed to upgrade client to SSL: {}", e),
)
})?;
builder.set_verify(SslVerifyMode::empty());
let connector = builder.build()
.configure()
.unwrap()
.use_server_name_indication(false)
.verify_hostname(false)
.connect("localhost:12321", sock)
.unwrap();
Ok(connector)
}
}
一个完整的例子是在Github上,大约 150 行,这是我能得到的最小的。
我收到此错误:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value:
WouldBlock(MidHandshakeSslStream {
stream: SslStream {
stream: TcpStream { addr: V4(127.0.0.1:52164), peer: V4(127.0.0.1:12321), fd: 12 },
ssl: Ssl { state: "SSLv2/v3 read server hello A", verify_result: X509VerifyResult { code: 0, error: "ok" } }
}, error: Error {
code: ErrorCode(2),
cause: Some(Io(Os {
code: 11,
kind: WouldBlock,
message: "Resource temporarily unavailable"
}))
}
})
我真的不知道那是什么意思...
(上个月我还创建了一个 ws-rs Github问题,因为我认为这可能是库或示例的问题)