| 1236 | } |
| 1237 | |
| 1238 | apr_status_t h2_session_set_prio(h2_session *session, h2_stream *stream, |
| 1239 | const h2_priority *prio) |
| 1240 | { |
| 1241 | apr_status_t status = APR_SUCCESS; |
| 1242 | nghttp2_stream *s_grandpa, *s_parent, *s; |
| 1243 | |
| 1244 | if (prio == NULL) { |
| 1245 | /* we treat this as a NOP */ |
| 1246 | return APR_SUCCESS; |
| 1247 | } |
| 1248 | s = nghttp2_session_find_stream(session->ngh2, stream->id); |
| 1249 | if (!s) { |
| 1250 | ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c1, |
| 1251 | H2_STRM_MSG(stream, "lookup of nghttp2_stream failed")); |
| 1252 | return APR_EINVAL; |
| 1253 | } |
| 1254 | |
| 1255 | s_parent = nghttp2_stream_get_parent(s); |
| 1256 | if (s_parent) { |
| 1257 | nghttp2_priority_spec ps; |
| 1258 | int id_parent, id_grandpa, w_parent, w; |
| 1259 | int rv = 0; |
| 1260 | const char *ptype = "AFTER"; |
| 1261 | h2_dependency dep = prio->dependency; |
| 1262 | |
| 1263 | id_parent = nghttp2_stream_get_stream_id(s_parent); |
| 1264 | s_grandpa = nghttp2_stream_get_parent(s_parent); |
| 1265 | if (s_grandpa) { |
| 1266 | id_grandpa = nghttp2_stream_get_stream_id(s_grandpa); |
| 1267 | } |
| 1268 | else { |
| 1269 | /* parent of parent does not exist, |
| 1270 | * only possible if parent == root */ |
| 1271 | dep = H2_DEPENDANT_AFTER; |
| 1272 | } |
| 1273 | |
| 1274 | switch (dep) { |
| 1275 | case H2_DEPENDANT_INTERLEAVED: |
| 1276 | /* PUSHed stream is to be interleaved with initiating stream. |
| 1277 | * It is made a sibling of the initiating stream and gets a |
| 1278 | * proportional weight [1, MAX_WEIGHT] of the initiaing |
| 1279 | * stream weight. |
| 1280 | */ |
| 1281 | ptype = "INTERLEAVED"; |
| 1282 | w_parent = nghttp2_stream_get_weight(s_parent); |
| 1283 | w = valid_weight(w_parent * ((float)prio->weight / NGHTTP2_MAX_WEIGHT)); |
| 1284 | nghttp2_priority_spec_init(&ps, id_grandpa, w, 0); |
| 1285 | break; |
| 1286 | |
| 1287 | case H2_DEPENDANT_BEFORE: |
| 1288 | /* PUSHed stream os to be sent BEFORE the initiating stream. |
| 1289 | * It gets the same weight as the initiating stream, replaces |
| 1290 | * that stream in the dependency tree and has the initiating |
| 1291 | * stream as child. |
| 1292 | */ |
| 1293 | ptype = "BEFORE"; |
| 1294 | w = w_parent = nghttp2_stream_get_weight(s_parent); |
| 1295 | nghttp2_priority_spec_init(&ps, stream->id, w_parent, 0); |
no test coverage detected