Convert a simple tail call to a loop
This commit is contained in:
parent
d6237cefcb
commit
a03a82e5e0
@ -121,16 +121,20 @@ pub struct LookupHost {
|
||||
impl Iterator for LookupHost {
|
||||
type Item = SocketAddr;
|
||||
fn next(&mut self) -> Option<SocketAddr> {
|
||||
let result;
|
||||
unsafe {
|
||||
if self.cur.is_null() { return None }
|
||||
result = sockaddr_to_addr(mem::transmute((*self.cur).ai_addr),
|
||||
(*self.cur).ai_addrlen as usize).ok();
|
||||
self.cur = (*self.cur).ai_next as *mut c::addrinfo;
|
||||
}
|
||||
match result {
|
||||
Some(r) => Some(r),
|
||||
None => self.next(),
|
||||
loop {
|
||||
unsafe {
|
||||
let cur = match self.cur.as_ref() {
|
||||
None => return None,
|
||||
Some(c) => c,
|
||||
};
|
||||
self.cur = cur.ai_next;
|
||||
match sockaddr_to_addr(mem::transmute(cur.ai_addr),
|
||||
cur.ai_addrlen as usize)
|
||||
{
|
||||
Ok(addr) => return Some(addr),
|
||||
Err(_) => continue,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user