Skip to content

Commit

Permalink
chore(dependencies): update spmc dev dependency to 0.3 (#1913)
Browse files Browse the repository at this point in the history
spmc 0.2.3 has been yanked on 2019-08-15

Passing to 0.2 requires a small change in the tests.
Changing the following (as was done in master branch)
  &'a spmc::Sender<Reply> -> &'a Mutex<spmc::Sender<Reply>>

This fixes the cargo issue telling us that he cannot handle smpc:
  error: failed to select a version for the requirement `spmc = "^0.2"`

Signed-off-by: Gabriel Ganne <[email protected]>
  • Loading branch information
GabrielGanne authored and seanmonstar committed Aug 22, 2019
1 parent e63368b commit a1609fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
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

0 comments on commit a1609fb

Please sign in to comment.