Last active
January 21, 2018 13:08
-
-
Save DoumanAsh/a4a547134e2826c01fbcff52381aea3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[inline] | |
| pub fn api_url() -> io::Result<RwLockReadGuard<'static, Option<SocketAddr>>> { | |
| lazy_static! { | |
| static ref API_ADDR: RwLock<Option<SocketAddr>> = RwLock::new(None); | |
| } | |
| loop { | |
| match API_ADDR.read() { | |
| Ok(read_lock) => match read_lock.as_ref() { | |
| Some(_) => return Ok(read_lock), | |
| None => () | |
| }, | |
| Err(_) => panic!("VNDB: api_url(): Poisoned RwLock") | |
| } | |
| match API_URL.to_socket_addrs() { | |
| Ok(mut iter) => match iter.next() { | |
| Some(addr) => { | |
| let mut write_lock = API_ADDR.write().expect("VNDB: api_url(): Poisoned RwLock"); | |
| *write_lock = Some(addr); | |
| }, | |
| None => return Err(io::Error::new(io::ErrorKind::AddrNotAvailable, "DNS query api.vndb.org returns nothing")) | |
| }, | |
| Err(error) => return Err(io::Error::new(io::ErrorKind::AddrNotAvailable, error)) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment