Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
int h2_stream_is_ready(h2_stream *stream)
{
if (stream->has_response) {
return 1;
}
else if (stream->out_buffer && get_first_headers_bucket(stream->out_buffer)) {
return 1;
}
return 0;
}
int h2_stream_was_closed(const h2_stream *stream)
{
switch (stream->state) {
case H2_SS_CLOSED:
case H2_SS_CLEANUP:
return 1;
default:
return 0;
}
}
apr_status_t h2_stream_in_consumed(h2_stream *stream, apr_off_t amount)
{
h2_session *session = stream->session;
if (amount > 0) {
apr_off_t consumed = amount;
while (consumed > 0) {
int len = (consumed > INT_MAX)? INT_MAX : (int)consumed;
nghttp2_session_consume(session->ngh2, stream->id, len);
consumed -= len;
}
#ifdef H2_NG2_LOCAL_WIN_SIZE
if (1) {
int cur_size = nghttp2_session_get_stream_local_window_size(
session->ngh2, stream->id);
int win = stream->in_window_size;
int thigh = win * 8/10;
int tlow = win * 2/10;
const int win_max = 2*1024*1024;
const int win_min = 32*1024;
/* Work in progress, probably should add directives for these
* values once this stabilizes somewhat. The general idea is
* to adapt stream window sizes if the input window changes
* a) very quickly (< good RTT) from full to empty
* b) only a little bit (> bad RTT)
* where in a) it grows and in b) it shrinks again.
*/
if (cur_size > thigh && amount > thigh && win < win_max) {
/* almost empty again with one reported consumption, how
* long did this take? */
long ms = apr_time_msec(apr_time_now() - stream->in_last_write);
if (ms < 40) {
win = H2MIN(win_max, win + (64*1024));
}
}
else if (cur_size < tlow && amount < tlow && win > win_min) {
/* staying full, for how long already? */
long ms = apr_time_msec(apr_time_now() - stream->in_last_write);
if (ms > 700) {
win = H2MAX(win_min, win - (32*1024));
}
}
if (win != stream->in_window_size) {
stream->in_window_size = win;
nghttp2_session_set_local_window_size(session->ngh2,
NGHTTP2_FLAG_NONE, stream->id, win);
}
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c,
"h2_stream(%ld-%d): consumed %ld bytes, window now %d/%d",
session->id, stream->id, (long)amount,
cur_size, stream->in_window_size);
}
#endif
}
return APR_SUCCESS;
}