-void maybe_send_keepalive(void)
-{
- if (time(NULL) - last_io_out >= allowed_lull) {
- if (!iobuf.msg.len && iobuf.out.len == iobuf.out_empty_len) {
- if (protocol_version < 29)
- return; /* there's nothing we can do */
- if (protocol_version >= 30)
- send_msg(MSG_NOOP, "", 0, 0);
- else {
- write_int(iobuf.out_fd, cur_flist->used);
- write_shortint(iobuf.out_fd, ITEM_IS_NEW);
- }
- }
- if (iobuf.msg.len)
+/* Older rsync versions used to send either a MSG_NOOP (protocol 30) or a
+ * raw-data-based keep-alive (protocol 29), both of which implied forwarding of
+ * the message through the sender. Since the new timeout method does not need
+ * any forwarding, we just send an empty MSG_DATA message, which works with all
+ * rsync versions. This avoids any message forwarding, and leaves the raw-data
+ * stream alone (since we can never be quite sure if that stream is in the
+ * right state for a keep-alive message). */
+void maybe_send_keepalive(time_t now, BOOL allow_flush)
+{
+ if (now - last_io_out >= allowed_lull) {
+ if (!iobuf.msg.len && iobuf.out.len == iobuf.out_empty_len)
+ send_msg(MSG_DATA, "", 0, 0);
+ if (!allow_flush) {
+ /* Let the caller worry about writing out the data. */
+ } else if (iobuf.msg.len)