diff options
author | Jonathon Orsi <jonathon.orsi@gmail.com> | 2019-09-23 14:40:38 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-09-23 15:12:42 -0400 |
commit | 045e74bb39d7743b774cfd2b889bc6ce1e1ad245 (patch) | |
tree | 93a8429860a40eabaee813e6f983f64aebd8afc7 /cli/resources.rs | |
parent | 4ff04ad96f27b7073e3478630ed249eedc76af2b (diff) |
feat: Add Deno.dialTLS()
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/resources.rs')
-rw-r--r-- | cli/resources.rs | 13 |
1 files changed, 13 insertions, 0 deletions
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<futures::task::Task>), TcpStream(tokio::net::TcpStream), + TlsStream(Box<TlsStream<TcpStream>>), HttpBody(HttpBody), Repl(Arc<Mutex<Repl>>), // 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<TcpStream>) -> 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(); |