Ticket #7743: 216769.txt

File 216769.txt, 917 bytes (added by nickm, 7 years ago)
Line 
1+  if (bytes_to_process < RELAY_PAYLOAD_SIZE) {
2+    ssize_t n_on_socket = 0;
3+    if (!package_partial)
4+      return 0;
5+
6+    if (! conn->min_to_package && /* count only first readable */
7+         ! TO_CONN(conn)->linked &&
8+        PREDICT_LIKELY(!sending_from_optimistic)) {
9+      n_on_socket = socket_get_n_readable(TO_CONN(conn)->s);
10+      if (n_on_socket > 0) {
11+        /* We don't have a full cell, and when we read more, we could fit more
12+         * in this cell.  Let's delay packaging until we have read either
13+         * all currently pending bytes, or until we have a full cell, whichever
14+         * comes first. */
15+        if (n_on_socket + bytes_to_process < RELAY_PAYLOAD_SIZE)
16+          conn->min_to_package = (uint16_t)(n_on_socket + bytes_to_process);
17+        else
18+          conn->min_to_package = RELAY_PAYLOAD_SIZE;
19+        return 0;
20+      }
21+    }
22+  }
23+  conn->min_to_package = 0;