@@ -179,6 +179,10 @@ int http_v2_send_frame (manapi::net::http::http_v2_t *ctx, int frame_type, uint
179179 true , manapi::ev::WRITE);
180180 manapi_log_trace (manapi::debug::LOG_TRACE_LOW, " http2: wait write event" );
181181 }
182+ // else {
183+ // manapi_log_trace(manapi::debug::LOG_TRACE_LOW, "http2: blocked flags&HTTP2_CTX_FLAG_BLOCK_WRITE=%d "
184+ // "is_writable(conn)=%d", ctx->flags & manapi::net::http::HTTP2_CTX_FLAG_BLOCK_WRITE, ctx->worker->is_writable(ctx->conn));
185+ // }
182186
183187 return manapi::ERR_OK;
184188}
@@ -701,20 +705,35 @@ int manapi::net::http::http_v2_on_write(http_v2_t *ctx) MANAPIHTTP_NOEXCEPT {
701705 ctx->flags ^= HTTP2_CTX_FLAG_BLOCK_WRITE;
702706
703707 bool no_one = true ;
704- for (const auto &priority : *ctx->priorities ) {
708+ // !!! IN PRIORITY LOOP WE MUST KNOW THAT THE PREVIUS PRIORITY CANT BE CHANGED !!!
709+ auto prev_priority = ctx->priorities ->end ();
710+ for (auto priority = ctx->priorities ->begin (); priority != ctx->priorities ->end (); ) {
705711 // auto &conn = (*priority.second);
706- auto const data = priority. second ->as <http_v2_stream_t >();
712+ auto const data = priority-> second ->as <http_v2_stream_t >();
707713 if (ctx->flags & HTTP2_CTX_FLAG_BLOCK_WRITE) {
708714 break ;
709715 }
710716
711- auto rhs = http_v2_stream_on_write (priority. second , data);
717+ auto rhs = http_v2_stream_on_write (priority-> second , data);
712718
713719 if (rhs)
714720 no_one = false ;
715721
716722 manapi_log_trace (manapi::debug::LOG_TRACE_LOW, " http2: write event received sid=%u s_write_window=%d processed=%d" ,
717723 data->id , ctx->write_window , rhs);
724+
725+ if (ctx->priorities ->empty ()) {
726+ break ;
727+ }
728+
729+ auto next_prev_priority = prev_priority != ctx->priorities ->end () ? std::next (prev_priority) : ctx->priorities ->begin ();
730+ if (next_prev_priority == priority) {
731+ prev_priority = priority;
732+ ++priority;
733+ }
734+ else {
735+ priority = next_prev_priority;
736+ }
718737 }
719738
720739 if (no_one)
@@ -2508,7 +2527,8 @@ ssize_t manapi::net::http::http_v2_write(const worker::shared_conn &conn, ev::bu
25082527
25092528 res += size;
25102529
2511- if (!s->ctx ->http_v2_worker ->is_writable (conn))
2530+ if (!s->ctx ->http_v2_worker ->is_writable (conn)
2531+ || (s->ctx ->flags & HTTP2_CTX_FLAG_BLOCK_WRITE))
25122532 break ;
25132533
25142534 if (lencut) {
@@ -2522,6 +2542,16 @@ ssize_t manapi::net::http::http_v2_write(const worker::shared_conn &conn, ev::bu
25222542 nbuff -= pnbuff;
25232543 }
25242544
2545+ auto left = static_cast <int >(copy - res);
2546+ if (left) {
2547+ s->ctx ->write_window += left;
2548+ s->write_window += left;
2549+ if (s->write_window == left) {
2550+ if (http_v2_update_priority (s->ctx , conn, s)) {
2551+ return -1 ;
2552+ }
2553+ }
2554+ }
25252555 s->transfered_k += static_cast <int >(res);
25262556
25272557 if (finish && res == copy) {
0 commit comments