Skip to content

Instantly share code, notes, and snippets.

@geoffjay
Created January 8, 2019 22:36
Show Gist options
  • Save geoffjay/7c57d80a874ef7b8d53d807462dc0883 to your computer and use it in GitHub Desktop.
Save geoffjay/7c57d80a874ef7b8d53d807462dc0883 to your computer and use it in GitHub Desktop.
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