mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Proper error handling when connecting to the server.
This commit is contained in:
parent
e9c3357e41
commit
65d1c1bf8e
2 changed files with 44 additions and 20 deletions
|
@ -28,9 +28,27 @@ pub fn connect(
|
|||
let (addr, connect_url) = match *proxy {
|
||||
Some(ref url) => {
|
||||
info!("Using proxy \"{}\"", url);
|
||||
(url.to_socket_addrs().unwrap().next().unwrap(), Some(addr))
|
||||
match url.to_socket_addrs().and_then(|mut iter| {
|
||||
iter.next().ok_or(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
"Can't resolve proxy server address",
|
||||
))
|
||||
}) {
|
||||
Ok(socket_addr) => (socket_addr, Some(addr)),
|
||||
Err(error) => return Box::new(futures::future::err(error)),
|
||||
}
|
||||
}
|
||||
None => {
|
||||
match addr.to_socket_addrs().and_then(|mut iter| {
|
||||
iter.next().ok_or(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
"Can't resolve server address",
|
||||
))
|
||||
}) {
|
||||
Ok(socket_addr) => (socket_addr, None),
|
||||
Err(error) => return Box::new(futures::future::err(error)),
|
||||
}
|
||||
}
|
||||
None => (addr.to_socket_addrs().unwrap().next().unwrap(), None),
|
||||
};
|
||||
|
||||
let socket = TcpStream::connect(&addr, handle);
|
||||
|
|
|
@ -460,7 +460,8 @@ impl Future for Main {
|
|||
progress = true;
|
||||
}
|
||||
|
||||
if let Async::Ready(session) = self.connect.poll().unwrap() {
|
||||
match self.connect.poll() {
|
||||
Ok(Async::Ready(session)) => {
|
||||
self.connect = Box::new(futures::future::empty());
|
||||
let mixer_config = self.mixer_config.clone();
|
||||
let mixer = (self.mixer)(Some(mixer_config));
|
||||
|
@ -482,6 +483,11 @@ impl Future for Main {
|
|||
|
||||
progress = true;
|
||||
}
|
||||
Ok(Async::NotReady) => (),
|
||||
Err(_) => {
|
||||
self.connect = Box::new(futures::future::empty());
|
||||
}
|
||||
}
|
||||
|
||||
if let Async::Ready(Some(())) = self.signal.poll().unwrap() {
|
||||
trace!("Ctrl-C received");
|
||||
|
|
Loading…
Reference in a new issue