Big-bang update tokio, warp, futures, & hyper to new versions.
This commit is contained in:
parent
1273b4adff
commit
00ec517e78
12 changed files with 497 additions and 1076 deletions
1413
Cargo.lock
generated
1413
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
14
Cargo.toml
14
Cargo.toml
|
@ -10,17 +10,15 @@ bytes = "^0.5"
|
||||||
clap = "^2.33.0"
|
clap = "^2.33.0"
|
||||||
custom_error = "^1.7"
|
custom_error = "^1.7"
|
||||||
env_logger = "^0.7"
|
env_logger = "^0.7"
|
||||||
futures = "0.1.29"
|
futures = "^0.3"
|
||||||
futures3 = { package = "futures-preview", version="0.3.0-alpha", features = ["compat"] }
|
http = "^0.2"
|
||||||
http = "^0.1.18"
|
hyper = "^0.13"
|
||||||
hyper = "^0.12.35"
|
|
||||||
hyper13 = { package = "hyper", version="0.13.0-alpha.4", features = ["unstable-stream"] }
|
|
||||||
log = "^0.4.8"
|
log = "^0.4.8"
|
||||||
matches = "^0.1.8"
|
matches = "^0.1.8"
|
||||||
odds = { version = "0.3.1", features = ["std-vec"] }
|
odds = { version = "0.3.1", features = ["std-vec"] }
|
||||||
tokio = "0.1.22"
|
tokio = { version="^0.2", features = ["io-std", "tcp", "macros", "rt-threaded", "time"] }
|
||||||
tokio2 = { package = "tokio", version="0.2.0-alpha.6" }
|
|
||||||
tokio-codec = "0.1.1"
|
tokio-codec = "0.1.1"
|
||||||
tokio-io = "0.1.12"
|
tokio-io = "0.1.12"
|
||||||
warp = "0.1.20"
|
tokio-util = "^0.3"
|
||||||
|
warp = "^0.2"
|
||||||
weak-table = "^0.2.3"
|
weak-table = "^0.2.3"
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::sync::{
|
||||||
Mutex
|
Mutex
|
||||||
};
|
};
|
||||||
|
|
||||||
use futures3::{
|
use futures::{
|
||||||
channel::mpsc::{
|
channel::mpsc::{
|
||||||
channel as mpsc_channel,
|
channel as mpsc_channel,
|
||||||
Sender,
|
Sender,
|
||||||
|
@ -16,7 +16,7 @@ use futures3::{
|
||||||
},
|
},
|
||||||
Sink,
|
Sink,
|
||||||
Stream,
|
Stream,
|
||||||
Never
|
never::Never,
|
||||||
};
|
};
|
||||||
use odds::vec::VecExt;
|
use odds::vec::VecExt;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use bytes::{Buf, Bytes, BytesMut};
|
use bytes::{Buf, Bytes, BytesMut};
|
||||||
use futures3::prelude::*;
|
use futures::prelude::*;
|
||||||
use std::{
|
use std::{
|
||||||
io::Cursor,
|
io::Cursor,
|
||||||
mem,
|
mem,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use clap::{App, AppSettings, ArgMatches, SubCommand};
|
use clap::{App, AppSettings, ArgMatches, SubCommand};
|
||||||
use tokio2::runtime::Runtime;
|
|
||||||
|
|
||||||
use super::stdin_stream;
|
use super::stdin_stream;
|
||||||
use webmetro::{
|
use webmetro::{
|
||||||
|
@ -17,19 +16,18 @@ pub fn options() -> App<'static, 'static> {
|
||||||
.about("Dumps WebM parsing events from parsing stdin")
|
.about("Dumps WebM parsing events from parsing stdin")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(_args: &ArgMatches) -> Result<(), WebmetroError> {
|
#[tokio::main]
|
||||||
|
pub async fn run(_args: &ArgMatches) -> Result<(), WebmetroError> {
|
||||||
|
|
||||||
let mut events = stdin_stream().parse_ebml();
|
let mut events = stdin_stream().parse_ebml();
|
||||||
|
|
||||||
Runtime::new().unwrap().block_on(async {
|
while let Some(element) = events.next().await? {
|
||||||
while let Some(element) = events.next().await? {
|
match element {
|
||||||
match element {
|
// suppress printing byte arrays
|
||||||
// suppress printing byte arrays
|
Tracks(slice) => println!("Tracks[{}]", slice.len()),
|
||||||
Tracks(slice) => println!("Tracks[{}]", slice.len()),
|
SimpleBlock(SimpleBlock {timecode, ..}) => println!("SimpleBlock@{}", timecode),
|
||||||
SimpleBlock(SimpleBlock {timecode, ..}) => println!("SimpleBlock@{}", timecode),
|
other => println!("{:?}", other)
|
||||||
other => println!("{:?}", other)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
}
|
||||||
})
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||||
use futures3::prelude::*;
|
use futures::prelude::*;
|
||||||
use futures3::future::ready;
|
|
||||||
use tokio2::runtime::Runtime;
|
|
||||||
|
|
||||||
use super::stdin_stream;
|
use super::stdin_stream;
|
||||||
use webmetro::{
|
use webmetro::{
|
||||||
|
@ -30,7 +28,8 @@ pub fn options() -> App<'static, 'static> {
|
||||||
.help("Slow down output to \"real time\" speed as determined by the timestamps (useful for streaming static files)"))
|
.help("Slow down output to \"real time\" speed as determined by the timestamps (useful for streaming static files)"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
#[tokio::main]
|
||||||
|
pub async fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
||||||
let mut timecode_fixer = ChunkTimecodeFixer::new();
|
let mut timecode_fixer = ChunkTimecodeFixer::new();
|
||||||
let mut chunk_stream: Box<dyn TryStream<Item = Result<Chunk, WebmetroError>, Ok = Chunk, Error = WebmetroError> + Send + Unpin> = Box::new(
|
let mut chunk_stream: Box<dyn TryStream<Item = Result<Chunk, WebmetroError>, Ok = Chunk, Error = WebmetroError> + Send + Unpin> = Box::new(
|
||||||
stdin_stream()
|
stdin_stream()
|
||||||
|
@ -43,9 +42,10 @@ pub fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
||||||
chunk_stream = Box::new(Throttle::new(chunk_stream));
|
chunk_stream = Box::new(Throttle::new(chunk_stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
Runtime::new().unwrap().block_on(chunk_stream.try_for_each(|mut chunk| {
|
while let Some(chunk) = chunk_stream.next().await {
|
||||||
ready(chunk.try_for_each(|buffer|
|
chunk?.try_for_each(|buffer|
|
||||||
io::stdout().write_all(&buffer).map_err(WebmetroError::from)
|
io::stdout().write_all(&buffer)
|
||||||
))
|
)?;
|
||||||
}))
|
};
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures3::TryStreamExt;
|
use futures::{TryStream, TryStreamExt};
|
||||||
|
use tokio_util::codec::{BytesCodec, FramedRead};
|
||||||
use webmetro::error::WebmetroError;
|
use webmetro::error::WebmetroError;
|
||||||
|
|
||||||
pub mod dump;
|
pub mod dump;
|
||||||
|
@ -12,13 +13,13 @@ pub mod send;
|
||||||
/// An adapter that makes chunks of bytes from stdin available as a Stream;
|
/// An adapter that makes chunks of bytes from stdin available as a Stream;
|
||||||
/// is NOT actually async, and just uses blocking read. Don't use more than
|
/// is NOT actually async, and just uses blocking read. Don't use more than
|
||||||
/// one at once, who knows who gets which bytes.
|
/// one at once, who knows who gets which bytes.
|
||||||
pub fn stdin_stream() -> impl futures3::TryStream<
|
pub fn stdin_stream() -> impl TryStream<
|
||||||
Item = Result<Cursor<Bytes>, WebmetroError>,
|
Item = Result<Cursor<Bytes>, WebmetroError>,
|
||||||
Ok = Cursor<Bytes>,
|
Ok = Cursor<Bytes>,
|
||||||
Error = WebmetroError,
|
Error = WebmetroError,
|
||||||
> + Sized
|
> + Sized
|
||||||
+ Unpin {
|
+ Unpin {
|
||||||
tokio2::codec::FramedRead::new(tokio2::io::stdin(), tokio2::codec::BytesCodec::new())
|
FramedRead::new(tokio::io::stdin(), BytesCodec::new())
|
||||||
.map_ok(|bytes| Cursor::new(bytes.freeze()))
|
.map_ok(|bytes| Cursor::new(bytes.freeze()))
|
||||||
.map_err(WebmetroError::from)
|
.map_err(WebmetroError::from)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,19 +8,10 @@ use std::sync::{
|
||||||
use bytes::{Bytes, Buf};
|
use bytes::{Bytes, Buf};
|
||||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||||
use futures::{
|
use futures::{
|
||||||
Future,
|
never::Never,
|
||||||
Stream,
|
|
||||||
Sink,
|
|
||||||
stream::empty
|
|
||||||
};
|
|
||||||
use futures3::{
|
|
||||||
compat::{
|
|
||||||
Compat,
|
|
||||||
CompatSink,
|
|
||||||
Compat01As03,
|
|
||||||
},
|
|
||||||
Never,
|
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
Stream,
|
||||||
|
stream::FuturesUnordered,
|
||||||
};
|
};
|
||||||
use hyper::{
|
use hyper::{
|
||||||
Body,
|
Body,
|
||||||
|
@ -56,30 +47,29 @@ use webmetro::{
|
||||||
|
|
||||||
const BUFFER_LIMIT: usize = 2 * 1024 * 1024;
|
const BUFFER_LIMIT: usize = 2 * 1024 * 1024;
|
||||||
|
|
||||||
fn get_stream(channel: Handle) -> impl Stream<Item = Bytes, Error = WebmetroError> {
|
fn get_stream(channel: Handle) -> impl Stream<Item = Result<Bytes, WebmetroError>> {
|
||||||
let mut timecode_fixer = ChunkTimecodeFixer::new();
|
let mut timecode_fixer = ChunkTimecodeFixer::new();
|
||||||
Compat::new(Listener::new(channel).map(|c| Ok(c))
|
Listener::new(channel).map(|c| Ok(c))
|
||||||
.map_ok(move |chunk| timecode_fixer.process(chunk))
|
.map_ok(move |chunk| timecode_fixer.process(chunk))
|
||||||
.find_starting_point()
|
.find_starting_point()
|
||||||
.map_ok(|webm_chunk| webm_chunk.into_bytes())
|
.map_ok(|webm_chunk| webm_chunk.into_bytes())
|
||||||
.map_err(|err: Never| match err {}))
|
.map_err(|err: Never| match err {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn post_stream(channel: Handle, stream: impl Stream<Item = impl Buf, Error = warp::Error>) -> impl Stream<Item = Bytes, Error = WebmetroError> {
|
fn post_stream(channel: Handle, stream: impl Stream<Item = Result<impl Buf, warp::Error>> + Unpin) -> impl Stream<Item = Result<Bytes, WebmetroError>> {
|
||||||
let source = Compat01As03::new(stream
|
let source = stream
|
||||||
.map_err(WebmetroError::from))
|
.map_err(WebmetroError::from)
|
||||||
.parse_ebml().with_soft_limit(BUFFER_LIMIT)
|
.parse_ebml().with_soft_limit(BUFFER_LIMIT)
|
||||||
.chunk_webm().with_soft_limit(BUFFER_LIMIT);
|
.chunk_webm().with_soft_limit(BUFFER_LIMIT);
|
||||||
let sink = CompatSink::new(Transmitter::new(channel));
|
let sink = Transmitter::new(channel);
|
||||||
|
|
||||||
Compat::new(source).forward(sink.sink_map_err(|err| -> WebmetroError {match err {}}))
|
source.forward(sink.sink_map_err(|err| -> WebmetroError {match err {}}))
|
||||||
.into_stream()
|
.into_stream()
|
||||||
.map(|_| empty())
|
.map_ok(|_| Bytes::new())
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("{}", err);
|
warn!("{}", err);
|
||||||
err
|
err
|
||||||
})
|
})
|
||||||
.flatten()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn media_response(body: Body) -> Response<Body> {
|
fn media_response(body: Body) -> Response<Body> {
|
||||||
|
@ -99,7 +89,8 @@ pub fn options() -> App<'static, 'static> {
|
||||||
.required(true))
|
.required(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
#[tokio::main]
|
||||||
|
pub async fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
||||||
let channel_map = Arc::new(Mutex::new(WeakValueHashMap::<String, Weak<Mutex<Channel>>>::new()));
|
let channel_map = Arc::new(Mutex::new(WeakValueHashMap::<String, Weak<Mutex<Channel>>>::new()));
|
||||||
let addr_str = args.value_of("listen").ok_or("Listen address wasn't provided")?;
|
let addr_str = args.value_of("listen").ok_or("Listen address wasn't provided")?;
|
||||||
|
|
||||||
|
@ -122,13 +113,13 @@ pub fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
||||||
media_response(Body::empty())
|
media_response(Body::empty())
|
||||||
});
|
});
|
||||||
|
|
||||||
let get = channel.clone().and(warp::get2())
|
let get = channel.clone().and(warp::get())
|
||||||
.map(|(channel, name)| {
|
.map(|(channel, name)| {
|
||||||
info!("Listener Connected On Channel {}", name);
|
info!("Listener Connected On Channel {}", name);
|
||||||
media_response(Body::wrap_stream(get_stream(channel)))
|
media_response(Body::wrap_stream(get_stream(channel)))
|
||||||
});
|
});
|
||||||
|
|
||||||
let post_put = channel.clone().and(warp::post2().or(warp::put2()).unify())
|
let post_put = channel.clone().and(warp::post().or(warp::put()).unify())
|
||||||
.and(warp::body::stream()).map(|(channel, name), stream| {
|
.and(warp::body::stream()).map(|(channel, name), stream| {
|
||||||
info!("Source Connected On Channel {}", name);
|
info!("Source Connected On Channel {}", name);
|
||||||
Response::new(Body::wrap_stream(post_stream(channel, stream)))
|
Response::new(Body::wrap_stream(post_stream(channel, stream)))
|
||||||
|
@ -138,11 +129,9 @@ pub fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
||||||
.or(get)
|
.or(get)
|
||||||
.or(post_put);
|
.or(post_put);
|
||||||
|
|
||||||
let mut rt = tokio::runtime::Runtime::new()?;
|
let mut server_futures: FuturesUnordered<_> = addrs.map(|addr| warp::serve(routes.clone()).try_bind(addr)).collect();
|
||||||
|
|
||||||
for do_serve in addrs.map(|addr| warp::serve(routes.clone()).try_bind(addr)) {
|
while let Some(_) = server_futures.next().await {};
|
||||||
rt.spawn(do_serve);
|
|
||||||
}
|
|
||||||
|
|
||||||
rt.shutdown_on_idle().wait().map_err(|_| "Shutdown error.".into())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||||
use futures3::prelude::*;
|
use futures::prelude::*;
|
||||||
use hyper13::{client::HttpConnector, Body, Client, Request};
|
use hyper::{client::HttpConnector, Body, Client, Request};
|
||||||
use std::io::{stdout, Write};
|
use std::io::{stdout, Write};
|
||||||
use tokio2::runtime::Runtime;
|
|
||||||
|
|
||||||
use super::stdin_stream;
|
use super::stdin_stream;
|
||||||
use webmetro::{
|
use webmetro::{
|
||||||
|
@ -30,7 +29,8 @@ type BoxedChunkStream = Box<
|
||||||
+ Unpin,
|
+ Unpin,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
pub fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
#[tokio::main]
|
||||||
|
pub async fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
||||||
let mut timecode_fixer = ChunkTimecodeFixer::new();
|
let mut timecode_fixer = ChunkTimecodeFixer::new();
|
||||||
let mut chunk_stream: BoxedChunkStream = Box::new(
|
let mut chunk_stream: BoxedChunkStream = Box::new(
|
||||||
stdin_stream()
|
stdin_stream()
|
||||||
|
@ -60,12 +60,10 @@ pub fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
||||||
let request = Request::put(url_str).body(request_payload)?;
|
let request = Request::put(url_str).body(request_payload)?;
|
||||||
let client = Client::builder().build(HttpConnector::new());
|
let client = Client::builder().build(HttpConnector::new());
|
||||||
|
|
||||||
Runtime::new().unwrap().block_on(async {
|
let response = client.request(request).await?;
|
||||||
let response = client.request(request).await?;
|
let mut response_stream = response.into_body();
|
||||||
let mut response_stream = response.into_body();
|
while let Some(response_chunk) = response_stream.next().await.transpose()? {
|
||||||
while let Some(response_chunk) = response_stream.next().await.transpose()? {
|
stdout().write_all(&response_chunk)?;
|
||||||
stdout().write_all(&response_chunk)?;
|
}
|
||||||
}
|
Ok(())
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ custom_error!{pub WebmetroError
|
||||||
EbmlError{source: crate::ebml::EbmlError} = "EBML error: {source}",
|
EbmlError{source: crate::ebml::EbmlError} = "EBML error: {source}",
|
||||||
HttpError{source: http::Error} = "HTTP error: {source}",
|
HttpError{source: http::Error} = "HTTP error: {source}",
|
||||||
HyperError{source: hyper::Error} = "Hyper error: {source}",
|
HyperError{source: hyper::Error} = "Hyper error: {source}",
|
||||||
Hyper13Error{source: hyper13::Error} = "Hyper error: {source}",
|
|
||||||
IoError{source: std::io::Error} = "IO error: {source}",
|
IoError{source: std::io::Error} = "IO error: {source}",
|
||||||
WarpError{source: warp::Error} = "Warp error: {source}",
|
WarpError{source: warp::Error} = "Warp error: {source}",
|
||||||
ApplicationError{message: String} = "{message}"
|
ApplicationError{message: String} = "{message}"
|
||||||
|
|
|
@ -3,12 +3,13 @@ use std::task::{
|
||||||
Context,
|
Context,
|
||||||
Poll
|
Poll
|
||||||
};
|
};
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
|
|
||||||
use futures3::prelude::*;
|
use futures::prelude::*;
|
||||||
use tokio2::timer::{
|
use tokio::time::{
|
||||||
delay,
|
delay_until,
|
||||||
Delay
|
Delay,
|
||||||
|
Duration,
|
||||||
|
Instant,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::chunk::Chunk;
|
use crate::chunk::Chunk;
|
||||||
|
@ -105,7 +106,7 @@ impl<S> Throttle<S> {
|
||||||
Throttle {
|
Throttle {
|
||||||
stream: wrap,
|
stream: wrap,
|
||||||
start_time: now,
|
start_time: now,
|
||||||
sleep: delay(now)
|
sleep: delay_until(now)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
||||||
use futures3::stream::{Stream, StreamExt, TryStream};
|
use futures::stream::{Stream, StreamExt, TryStream};
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use crate::ebml::FromEbml;
|
use crate::ebml::FromEbml;
|
||||||
|
@ -112,7 +112,7 @@ impl<I: Buf, S: Stream<Item = Result<I, WebmetroError>> + Unpin> EbmlStreamingPa
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use futures3::{future::poll_fn, stream::StreamExt, FutureExt};
|
use futures::{future::poll_fn, stream::StreamExt, FutureExt};
|
||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
use std::task::Poll::*;
|
use std::task::Poll::*;
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ mod tests {
|
||||||
&ENCODE_WEBM_TEST_FILE[40..],
|
&ENCODE_WEBM_TEST_FILE[40..],
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut stream_parser = futures3::stream::iter(pieces.iter())
|
let mut stream_parser = futures::stream::iter(pieces.iter())
|
||||||
.map(|bytes| Ok(&bytes[..]))
|
.map(|bytes| Ok(&bytes[..]))
|
||||||
.parse_ebml();
|
.parse_ebml();
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ mod tests {
|
||||||
];
|
];
|
||||||
|
|
||||||
async {
|
async {
|
||||||
let mut parser = futures3::stream::iter(pieces.iter())
|
let mut parser = futures::stream::iter(pieces.iter())
|
||||||
.map(|bytes| Ok(&bytes[..]))
|
.map(|bytes| Ok(&bytes[..]))
|
||||||
.parse_ebml();
|
.parse_ebml();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue