Skip to content

fix(spmc): update spmc dependency 0.2 -> 0.3 as 0.2 has been yanked #1913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ rustc_version = "0.2"
futures-timer = "0.1"
num_cpus = "1.0"
pretty_env_logger = "0.3"
spmc = "0.2"
spmc = "0.3"
url = "1.0"
tokio-fs = "0.1"
tokio-mockstream = "1.1.0"
Expand Down
26 changes: 14 additions & 12 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::net::{TcpStream, Shutdown, SocketAddr};
use std::io::{self, Read, Write};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc;
use std::sync::{Arc};
use std::sync::{Arc, Mutex};
use std::net::{TcpListener as StdTcpListener};
use std::thread;
use std::time::Duration;
Expand Down Expand Up @@ -1739,7 +1739,7 @@ fn skips_content_length_and_body_for_304_responses() {
struct Serve {
addr: SocketAddr,
msg_rx: mpsc::Receiver<Msg>,
reply_tx: spmc::Sender<Reply>,
reply_tx: Mutex<spmc::Sender<Reply>>,
shutdown_signal: Option<oneshot::Sender<()>>,
thread: Option<thread::JoinHandle<()>>,
}
Expand Down Expand Up @@ -1772,7 +1772,7 @@ impl Serve {
Ok(buf)
}

fn reply(&self) -> ReplyBuilder {
fn reply(&self) -> ReplyBuilder<'_> {
ReplyBuilder {
tx: &self.reply_tx
}
Expand All @@ -1782,43 +1782,45 @@ impl Serve {
type BoxError = Box<dyn std::error::Error + Send + Sync>;

struct ReplyBuilder<'a> {
tx: &'a spmc::Sender<Reply>,
tx: &'a Mutex<spmc::Sender<Reply>>,
}

impl<'a> ReplyBuilder<'a> {
fn status(self, status: hyper::StatusCode) -> Self {
self.tx.send(Reply::Status(status)).unwrap();
self.tx.lock().unwrap().send(Reply::Status(status)).unwrap();
self
}

fn version(self, version: hyper::Version) -> Self {
self.tx.send(Reply::Version(version)).unwrap();
self.tx.lock().unwrap().send(Reply::Version(version)).unwrap();
self
}

fn header<V: AsRef<str>>(self, name: &str, value: V) -> Self {
let name = HeaderName::from_bytes(name.as_bytes()).expect("header name");
let value = HeaderValue::from_str(value.as_ref()).expect("header value");
self.tx.send(Reply::Header(name, value)).unwrap();
self.tx.lock().unwrap().send(Reply::Header(name, value)).unwrap();
self
}

fn body<T: AsRef<[u8]>>(self, body: T) {
self.tx.send(Reply::Body(body.as_ref().to_vec().into())).unwrap();
self.tx.lock().unwrap().send(Reply::Body(body.as_ref().to_vec().into())).unwrap();
}

fn body_stream(self, body: Body) {
self.tx.send(Reply::Body(body)).unwrap();
self.tx.lock().unwrap().send(Reply::Body(body)).unwrap();
}

fn error<E: Into<BoxError>>(self, err: E) {
self.tx.send(Reply::Error(err.into())).unwrap();
self.tx.lock().unwrap().send(Reply::Error(err.into())).unwrap();
}
}

impl<'a> Drop for ReplyBuilder<'a> {
fn drop(&mut self) {
let _ = self.tx.send(Reply::End);
if let Ok(mut tx) = self.tx.lock() {
let _ = tx.send(Reply::End);
}
}
}

Expand Down Expand Up @@ -2006,7 +2008,7 @@ impl ServeOptions {

Serve {
msg_rx: msg_rx,
reply_tx: reply_tx,
reply_tx: Mutex::new(reply_tx),
addr: addr,
shutdown_signal: Some(shutdown_tx),
thread: Some(thread),
Expand Down