#include "h2_h2.h"
#include "h2_util.h"
-#define WRITE_BUFFER_SIZE (128*1024)
+#define TLS_DATA_MAX (16*1024)
+
/* Calculated like this: assuming MTU 1500 bytes
* 1500 - 40 (IP) - 20 (TCP) - 40 (TCP options)
* - TLS overhead (60-100)
* ~= 1300 bytes */
#define WRITE_SIZE_INITIAL 1300
-/* Calculated like this: max TLS record size
- * 16*1024
- * - TLS overhead (60-100) */
-#define WRITE_SIZE_MAX (16*1024 - 100)
+/* Calculated like this: max TLS record size 16*1024
+ * - 40 (IP) - 20 (TCP) - 40 (TCP options)
+ * - TLS overhead (60-100)
+ * which seems to create less TCP packets overall
+ */
+#define WRITE_SIZE_MAX (TLS_DATA_MAX - 100)
+
+#define WRITE_BUFFER_SIZE (8*WRITE_SIZE_MAX)
apr_status_t h2_conn_io_init(h2_conn_io *io, conn_rec *c)
{
return h2_session_status_from_apr_status(status);
}
+static ssize_t on_data_source_read_length_cb(nghttp2_session *session,
+ uint8_t frame_type, int32_t stream_id,
+ int32_t session_remote_window_size,
+ int32_t stream_remote_window_size,
+ uint32_t remote_max_frame_size,
+ void *user_data)
+{
+ /* DATA frames add 9 bytes header plus 1 byte for padlen and additional
+ * padlen bytes. Keep below TLS maximum record size.
+ * TODO: respect pad bytes when we have that feature.
+ */
+ return (16*1024 - 10);
+}
+
#define NGH2_SET_CALLBACK(callbacks, name, fn)\
nghttp2_session_callbacks_set_##name##_callback(callbacks, fn)
NGH2_SET_CALLBACK(*pcb, on_begin_headers, on_begin_headers_cb);
NGH2_SET_CALLBACK(*pcb, on_header, on_header_cb);
NGH2_SET_CALLBACK(*pcb, send_data, on_send_data_cb);
+ NGH2_SET_CALLBACK(*pcb, data_source_read_length, on_data_source_read_length_cb);
return APR_SUCCESS;
}