From 045e74bb39d7743b774cfd2b889bc6ce1e1ad245 Mon Sep 17 00:00:00 2001 From: Jonathon Orsi Date: Mon, 23 Sep 2019 14:40:38 -0400 Subject: feat: Add Deno.dialTLS() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartek IwaƄczuk --- cli/resources.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'cli/resources.rs') diff --git a/cli/resources.rs b/cli/resources.rs index 3bce51afb..0fdb0e182 100644 --- a/cli/resources.rs +++ b/cli/resources.rs @@ -36,6 +36,7 @@ use tokio::io::{AsyncRead, AsyncWrite}; use tokio::net::TcpStream; use tokio::sync::mpsc; use tokio_process; +use tokio_rustls::client::TlsStream; pub type ResourceId = u32; // Sometimes referred to RID. @@ -89,6 +90,7 @@ enum Repr { // See: https://github.com/tokio-rs/tokio/issues/846 TcpListener(tokio::net::TcpListener, Option), TcpStream(tokio::net::TcpStream), + TlsStream(Box>), HttpBody(HttpBody), Repl(Arc>), // Enum size is bounded by the largest variant. @@ -134,6 +136,7 @@ fn inspect_repr(repr: &Repr) -> String { Repr::FsFile(_) => "fsFile", Repr::TcpListener(_, _) => "tcpListener", Repr::TcpStream(_) => "tcpStream", + Repr::TlsStream(_) => "tlsStream", Repr::HttpBody(_) => "httpBody", Repr::Repl(_) => "repl", Repr::Child(_) => "child", @@ -249,6 +252,7 @@ impl DenoAsyncRead for Resource { Repr::FsFile(ref mut f) => f.poll_read(buf), Repr::Stdin(ref mut f) => f.poll_read(buf), Repr::TcpStream(ref mut f) => f.poll_read(buf), + Repr::TlsStream(ref mut f) => f.poll_read(buf), Repr::HttpBody(ref mut f) => f.poll_read(buf), Repr::ChildStdout(ref mut f) => f.poll_read(buf), Repr::ChildStderr(ref mut f) => f.poll_read(buf), @@ -289,6 +293,7 @@ impl DenoAsyncWrite for Resource { Repr::Stdout(ref mut f) => f.poll_write(buf), Repr::Stderr(ref mut f) => f.poll_write(buf), Repr::TcpStream(ref mut f) => f.poll_write(buf), + Repr::TlsStream(ref mut f) => f.poll_write(buf), Repr::ChildStdin(ref mut f) => f.poll_write(buf), _ => { return Err(bad_resource()); @@ -332,6 +337,14 @@ pub fn add_tcp_stream(stream: tokio::net::TcpStream) -> Resource { Resource { rid } } +pub fn add_tls_stream(stream: TlsStream) -> Resource { + let rid = new_rid(); + let mut tg = RESOURCE_TABLE.lock().unwrap(); + let r = tg.insert(rid, Repr::TlsStream(Box::new(stream))); + assert!(r.is_none()); + Resource { rid } +} + pub fn add_reqwest_body(body: ReqwestDecoder) -> Resource { let rid = new_rid(); let mut tg = RESOURCE_TABLE.lock().unwrap(); -- cgit v1.2.3