Skip to content

Commit a1609fb

Browse files
GabrielGanneseanmonstar
authored andcommitted
chore(dependencies): update spmc dev dependency to 0.3 (#1913)
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]>
1 parent e63368b commit a1609fb

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ rustc_version = "0.2"
4848
futures-timer = "0.1"
4949
num_cpus = "1.0"
5050
pretty_env_logger = "0.3"
51-
spmc = "0.2"
51+
spmc = "0.3"
5252
url = "1.0"
5353
tokio-fs = "0.1"
5454
tokio-mockstream = "1.1.0"

tests/server.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::net::{TcpStream, Shutdown, SocketAddr};
1616
use std::io::{self, Read, Write};
1717
use std::sync::atomic::{AtomicBool, Ordering};
1818
use std::sync::mpsc;
19-
use std::sync::{Arc};
19+
use std::sync::{Arc, Mutex};
2020
use std::net::{TcpListener as StdTcpListener};
2121
use std::thread;
2222
use std::time::Duration;
@@ -1739,7 +1739,7 @@ fn skips_content_length_and_body_for_304_responses() {
17391739
struct Serve {
17401740
addr: SocketAddr,
17411741
msg_rx: mpsc::Receiver<Msg>,
1742-
reply_tx: spmc::Sender<Reply>,
1742+
reply_tx: Mutex<spmc::Sender<Reply>>,
17431743
shutdown_signal: Option<oneshot::Sender<()>>,
17441744
thread: Option<thread::JoinHandle<()>>,
17451745
}
@@ -1772,7 +1772,7 @@ impl Serve {
17721772
Ok(buf)
17731773
}
17741774

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

17841784
struct ReplyBuilder<'a> {
1785-
tx: &'a spmc::Sender<Reply>,
1785+
tx: &'a Mutex<spmc::Sender<Reply>>,
17861786
}
17871787

17881788
impl<'a> ReplyBuilder<'a> {
17891789
fn status(self, status: hyper::StatusCode) -> Self {
1790-
self.tx.send(Reply::Status(status)).unwrap();
1790+
self.tx.lock().unwrap().send(Reply::Status(status)).unwrap();
17911791
self
17921792
}
17931793

17941794
fn version(self, version: hyper::Version) -> Self {
1795-
self.tx.send(Reply::Version(version)).unwrap();
1795+
self.tx.lock().unwrap().send(Reply::Version(version)).unwrap();
17961796
self
17971797
}
17981798

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

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

18101810
fn body_stream(self, body: Body) {
1811-
self.tx.send(Reply::Body(body)).unwrap();
1811+
self.tx.lock().unwrap().send(Reply::Body(body)).unwrap();
18121812
}
18131813

18141814
fn error<E: Into<BoxError>>(self, err: E) {
1815-
self.tx.send(Reply::Error(err.into())).unwrap();
1815+
self.tx.lock().unwrap().send(Reply::Error(err.into())).unwrap();
18161816
}
18171817
}
18181818

18191819
impl<'a> Drop for ReplyBuilder<'a> {
18201820
fn drop(&mut self) {
1821-
let _ = self.tx.send(Reply::End);
1821+
if let Ok(mut tx) = self.tx.lock() {
1822+
let _ = tx.send(Reply::End);
1823+
}
18221824
}
18231825
}
18241826

@@ -2006,7 +2008,7 @@ impl ServeOptions {
20062008

20072009
Serve {
20082010
msg_rx: msg_rx,
2009-
reply_tx: reply_tx,
2011+
reply_tx: Mutex::new(reply_tx),
20102012
addr: addr,
20112013
shutdown_signal: Some(shutdown_tx),
20122014
thread: Some(thread),

0 commit comments

Comments
 (0)