Big-bang update tokio, warp, futures, & hyper to new versions.
This commit is contained in:
parent
1273b4adff
commit
00ec517e78
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"
|
||||
custom_error = "^1.7"
|
||||
env_logger = "^0.7"
|
||||
futures = "0.1.29"
|
||||
futures3 = { package = "futures-preview", version="0.3.0-alpha", features = ["compat"] }
|
||||
http = "^0.1.18"
|
||||
hyper = "^0.12.35"
|
||||
hyper13 = { package = "hyper", version="0.13.0-alpha.4", features = ["unstable-stream"] }
|
||||
futures = "^0.3"
|
||||
http = "^0.2"
|
||||
hyper = "^0.13"
|
||||
log = "^0.4.8"
|
||||
matches = "^0.1.8"
|
||||
odds = { version = "0.3.1", features = ["std-vec"] }
|
||||
tokio = "0.1.22"
|
||||
tokio2 = { package = "tokio", version="0.2.0-alpha.6" }
|
||||
tokio = { version="^0.2", features = ["io-std", "tcp", "macros", "rt-threaded", "time"] }
|
||||
tokio-codec = "0.1.1"
|
||||
tokio-io = "0.1.12"
|
||||
warp = "0.1.20"
|
||||
tokio-util = "^0.3"
|
||||
warp = "^0.2"
|
||||
weak-table = "^0.2.3"
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::sync::{
|
|||
Mutex
|
||||
};
|
||||
|
||||
use futures3::{
|
||||
use futures::{
|
||||
channel::mpsc::{
|
||||
channel as mpsc_channel,
|
||||
Sender,
|
||||
|
@ -16,7 +16,7 @@ use futures3::{
|
|||
},
|
||||
Sink,
|
||||
Stream,
|
||||
Never
|
||||
never::Never,
|
||||
};
|
||||
use odds::vec::VecExt;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use bytes::{Buf, Bytes, BytesMut};
|
||||
use futures3::prelude::*;
|
||||
use futures::prelude::*;
|
||||
use std::{
|
||||
io::Cursor,
|
||||
mem,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use clap::{App, AppSettings, ArgMatches, SubCommand};
|
||||
use tokio2::runtime::Runtime;
|
||||
|
||||
use super::stdin_stream;
|
||||
use webmetro::{
|
||||
|
@ -17,19 +16,18 @@ pub fn options() -> App<'static, 'static> {
|
|||
.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();
|
||||
|
||||
Runtime::new().unwrap().block_on(async {
|
||||
while let Some(element) = events.next().await? {
|
||||
match element {
|
||||
// suppress printing byte arrays
|
||||
Tracks(slice) => println!("Tracks[{}]", slice.len()),
|
||||
SimpleBlock(SimpleBlock {timecode, ..}) => println!("SimpleBlock@{}", timecode),
|
||||
other => println!("{:?}", other)
|
||||
}
|
||||
while let Some(element) = events.next().await? {
|
||||
match element {
|
||||
// suppress printing byte arrays
|
||||
Tracks(slice) => println!("Tracks[{}]", slice.len()),
|
||||
SimpleBlock(SimpleBlock {timecode, ..}) => println!("SimpleBlock@{}", timecode),
|
||||
other => println!("{:?}", other)
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -4,9 +4,7 @@ use std::{
|
|||
};
|
||||
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use futures3::prelude::*;
|
||||
use futures3::future::ready;
|
||||
use tokio2::runtime::Runtime;
|
||||
use futures::prelude::*;
|
||||
|
||||
use super::stdin_stream;
|
||||
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)"))
|
||||
}
|
||||
|
||||
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 chunk_stream: Box<dyn TryStream<Item = Result<Chunk, WebmetroError>, Ok = Chunk, Error = WebmetroError> + Send + Unpin> = Box::new(
|
||||
stdin_stream()
|
||||
|
@ -43,9 +42,10 @@ pub fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
|||
chunk_stream = Box::new(Throttle::new(chunk_stream));
|
||||
}
|
||||
|
||||
Runtime::new().unwrap().block_on(chunk_stream.try_for_each(|mut chunk| {
|
||||
ready(chunk.try_for_each(|buffer|
|
||||
io::stdout().write_all(&buffer).map_err(WebmetroError::from)
|
||||
))
|
||||
}))
|
||||
while let Some(chunk) = chunk_stream.next().await {
|
||||
chunk?.try_for_each(|buffer|
|
||||
io::stdout().write_all(&buffer)
|
||||
)?;
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use std::io::Cursor;
|
||||
|
||||
use bytes::Bytes;
|
||||
use futures3::TryStreamExt;
|
||||
use futures::{TryStream, TryStreamExt};
|
||||
use tokio_util::codec::{BytesCodec, FramedRead};
|
||||
use webmetro::error::WebmetroError;
|
||||
|
||||
pub mod dump;
|
||||
|
@ -12,13 +13,13 @@ pub mod send;
|
|||
/// 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
|
||||
/// 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>,
|
||||
Ok = Cursor<Bytes>,
|
||||
Error = WebmetroError,
|
||||
> + Sized
|
||||
+ 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_err(WebmetroError::from)
|
||||
}
|
||||
|
|
|
@ -8,19 +8,10 @@ use std::sync::{
|
|||
use bytes::{Bytes, Buf};
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use futures::{
|
||||
Future,
|
||||
Stream,
|
||||
Sink,
|
||||
stream::empty
|
||||
};
|
||||
use futures3::{
|
||||
compat::{
|
||||
Compat,
|
||||
CompatSink,
|
||||
Compat01As03,
|
||||
},
|
||||
Never,
|
||||
never::Never,
|
||||
prelude::*,
|
||||
Stream,
|
||||
stream::FuturesUnordered,
|
||||
};
|
||||
use hyper::{
|
||||
Body,
|
||||
|
@ -56,30 +47,29 @@ use webmetro::{
|
|||
|
||||
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();
|
||||
Compat::new(Listener::new(channel).map(|c| Ok(c))
|
||||
Listener::new(channel).map(|c| Ok(c))
|
||||
.map_ok(move |chunk| timecode_fixer.process(chunk))
|
||||
.find_starting_point()
|
||||
.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> {
|
||||
let source = Compat01As03::new(stream
|
||||
.map_err(WebmetroError::from))
|
||||
fn post_stream(channel: Handle, stream: impl Stream<Item = Result<impl Buf, warp::Error>> + Unpin) -> impl Stream<Item = Result<Bytes, WebmetroError>> {
|
||||
let source = stream
|
||||
.map_err(WebmetroError::from)
|
||||
.parse_ebml().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()
|
||||
.map(|_| empty())
|
||||
.map_ok(|_| Bytes::new())
|
||||
.map_err(|err| {
|
||||
warn!("{}", err);
|
||||
err
|
||||
})
|
||||
.flatten()
|
||||
}
|
||||
|
||||
fn media_response(body: Body) -> Response<Body> {
|
||||
|
@ -99,7 +89,8 @@ pub fn options() -> App<'static, 'static> {
|
|||
.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 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())
|
||||
});
|
||||
|
||||
let get = channel.clone().and(warp::get2())
|
||||
let get = channel.clone().and(warp::get())
|
||||
.map(|(channel, name)| {
|
||||
info!("Listener Connected On Channel {}", name);
|
||||
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| {
|
||||
info!("Source Connected On Channel {}", name);
|
||||
Response::new(Body::wrap_stream(post_stream(channel, stream)))
|
||||
|
@ -138,11 +129,9 @@ pub fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
|||
.or(get)
|
||||
.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)) {
|
||||
rt.spawn(do_serve);
|
||||
}
|
||||
while let Some(_) = server_futures.next().await {};
|
||||
|
||||
rt.shutdown_on_idle().wait().map_err(|_| "Shutdown error.".into())
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use futures3::prelude::*;
|
||||
use hyper13::{client::HttpConnector, Body, Client, Request};
|
||||
use futures::prelude::*;
|
||||
use hyper::{client::HttpConnector, Body, Client, Request};
|
||||
use std::io::{stdout, Write};
|
||||
use tokio2::runtime::Runtime;
|
||||
|
||||
use super::stdin_stream;
|
||||
use webmetro::{
|
||||
|
@ -30,7 +29,8 @@ type BoxedChunkStream = Box<
|
|||
+ 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 chunk_stream: BoxedChunkStream = Box::new(
|
||||
stdin_stream()
|
||||
|
@ -60,12 +60,10 @@ pub fn run(args: &ArgMatches) -> Result<(), WebmetroError> {
|
|||
let request = Request::put(url_str).body(request_payload)?;
|
||||
let client = Client::builder().build(HttpConnector::new());
|
||||
|
||||
Runtime::new().unwrap().block_on(async {
|
||||
let response = client.request(request).await?;
|
||||
let mut response_stream = response.into_body();
|
||||
while let Some(response_chunk) = response_stream.next().await.transpose()? {
|
||||
stdout().write_all(&response_chunk)?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
let response = client.request(request).await?;
|
||||
let mut response_stream = response.into_body();
|
||||
while let Some(response_chunk) = response_stream.next().await.transpose()? {
|
||||
stdout().write_all(&response_chunk)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ custom_error!{pub WebmetroError
|
|||
EbmlError{source: crate::ebml::EbmlError} = "EBML error: {source}",
|
||||
HttpError{source: http::Error} = "HTTP error: {source}",
|
||||
HyperError{source: hyper::Error} = "Hyper error: {source}",
|
||||
Hyper13Error{source: hyper13::Error} = "Hyper error: {source}",
|
||||
IoError{source: std::io::Error} = "IO error: {source}",
|
||||
WarpError{source: warp::Error} = "Warp error: {source}",
|
||||
ApplicationError{message: String} = "{message}"
|
||||
|
|
|
@ -3,12 +3,13 @@ use std::task::{
|
|||
Context,
|
||||
Poll
|
||||
};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use futures3::prelude::*;
|
||||
use tokio2::timer::{
|
||||
delay,
|
||||
Delay
|
||||
use futures::prelude::*;
|
||||
use tokio::time::{
|
||||
delay_until,
|
||||
Delay,
|
||||
Duration,
|
||||
Instant,
|
||||
};
|
||||
|
||||
use crate::chunk::Chunk;
|
||||
|
@ -105,7 +106,7 @@ impl<S> Throttle<S> {
|
|||
Throttle {
|
||||
stream: wrap,
|
||||
start_time: now,
|
||||
sleep: delay(now)
|
||||
sleep: delay_until(now)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
||||
use futures3::stream::{Stream, StreamExt, TryStream};
|
||||
use futures::stream::{Stream, StreamExt, TryStream};
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use crate::ebml::FromEbml;
|
||||
|
@ -112,7 +112,7 @@ impl<I: Buf, S: Stream<Item = Result<I, WebmetroError>> + Unpin> EbmlStreamingPa
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use futures3::{future::poll_fn, stream::StreamExt, FutureExt};
|
||||
use futures::{future::poll_fn, stream::StreamExt, FutureExt};
|
||||
use matches::assert_matches;
|
||||
use std::task::Poll::*;
|
||||
|
||||
|
@ -129,7 +129,7 @@ mod tests {
|
|||
&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[..]))
|
||||
.parse_ebml();
|
||||
|
||||
|
@ -181,7 +181,7 @@ mod tests {
|
|||
];
|
||||
|
||||
async {
|
||||
let mut parser = futures3::stream::iter(pieces.iter())
|
||||
let mut parser = futures::stream::iter(pieces.iter())
|
||||
.map(|bytes| Ok(&bytes[..]))
|
||||
.parse_ebml();
|
||||
|
||||
|
|
Loading…
Reference in New Issue