message: copy send/recv buffer as much as possible
diff: @@ -280,7 +280,8 @@ impl TcpTun {
  }
  // Check if readable
  - if socket.can_recv() && !control.recv_buffer.is_full() {
  + let mut has_received = false;
  + while socket.can_recv() && !control.recv_buffer.is_full() {
  let result = socket.recv(|buffer| {
  let n = control.recv_buffer.enqueue_slice(buffer);
  (n, ())
  @@ -288,20 +289,26 @@ impl TcpTun {
  match result {
  Ok(..) => {
  - if let Some(waker) = control.recv_waker.take() {
  - waker.wake();
  - }
  + has_received = true;
  }
  Err(err) => {
  error!("socket recv error: {}", err);
  sockets_to_remove.push(socket_handle);
  close_socket_control(&mut *control);
  + break;
  + }
  }
  }
  +
  + if has_received {
  + if let Some(waker) = control.recv_waker.take() {
  + waker.wake();
  + }
  }
  // Check if writable
  - if socket.can_send() && !control.send_buffer.is_empty() {
  + let mut has_sent = false;
  + while socket.can_send() && !control.send_buffer.is_empty() {
  let result = socket.send(|buffer| {
  let n = control.send_buffer.dequeue_slice(buffer);
  (n, ())
  @@ -309,16 +316,21 @@ impl TcpTun {
  match result {
  Ok(..) => {
  - if let Some(waker) = control.send_waker.take() {
  - waker.wake();
  - }
  + has_sent = true;
  }
  Err(err) => {
  error!("socket send error: {}", err);
  sockets_to_remove.push(socket_handle);
  close_socket_control(&mut *control);
  + break;
  + }
  }
  }
  +
  + if has_sent {
  + if let Some(waker) = control.send_waker.take() {
  + waker.wake();
  + }
  }
  }
  