Created
January 8, 2019 22:36
-
-
Save geoffjay/7c57d80a874ef7b8d53d807462dc0883 to your computer and use it in GitHub Desktop.
This file contains 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
pub fn recv(&mut self) -> Result<Vec<Vec<u8>>, Box<Error>> { | |
let poller = self.poller.as_mut().unwrap(); | |
let sock = poller.wait::<ZSock>(Some(self.timeout.as_millis() as u32)); | |
let mut resp: Vec<Vec<u8>> = Vec::new(); | |
match sock { | |
Some(mut sock) => { | |
let msg = ZMsg::recv::<ZSock>(&mut sock).unwrap(); | |
sock.flush(); | |
// Don't attempt to handle errors, just assert | |
if msg.size() < 4 { | |
panic!("client: msg length < 4"); | |
} | |
let mut num = 0; | |
while let Some(bytes) = msg.popbytes().unwrap() { | |
match Some(bytes) { | |
Some(bytes) => { | |
match num { | |
0 => { | |
if std::str::from_utf8(&bytes).unwrap() != "" { | |
panic!("client: msg[0] != \"\""); | |
} | |
}, | |
1 => { | |
if std::str::from_utf8(&bytes).unwrap() != mdp::MDPC_CLIENT { | |
panic!("client: msg[1] != MDPC_CLIENT"); | |
} | |
}, | |
_ => {}, | |
} | |
resp.push(bytes.to_vec()); | |
}, | |
None => panic!("Failed to receive frame bytes"), | |
} | |
num = num + 1; | |
} | |
}, | |
None => {}, | |
} | |
Ok(resp) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment