in netbench/src/duplex.rs [77:110]
fn poll_send(
&mut self,
_owner: Owner,
_id: u64,
bytes: u64,
cx: &mut Context,
) -> Poll<Result<u64>> {
let mut sent: u64 = 0;
while sent < bytes {
let to_send = (bytes - sent) as usize;
let to_send = to_send.min(SEND_BUFFER_SIZE);
let to_send = &SEND_BUFFER[0..to_send];
match self.inner.as_mut().poll_write(cx, to_send) {
Poll::Ready(result) => {
sent += result? as u64;
}
Poll::Pending if sent == 0 => {
return Poll::Pending;
}
Poll::Pending => {
break;
}
}
}
// if the whole buffer was accepted, make sure it's flushed to the socket
if sent == bytes {
if let Poll::Ready(res) = self.inner.as_mut().poll_flush(cx) {
res?;
}
}
Ok(sent).into()
}