Lines Matching refs:ctx

157   ((struct cf_h2_ctx *)(cf)->ctx)->call_data
161 static void cf_h2_ctx_init(struct cf_h2_ctx *ctx, bool via_h1_upgrade) in cf_h2_ctx_init() argument
163 Curl_bufcp_init(&ctx->stream_bufcp, H2_CHUNK_SIZE, H2_STREAM_POOL_SPARES); in cf_h2_ctx_init()
164 Curl_bufq_initp(&ctx->inbufq, &ctx->stream_bufcp, H2_NW_RECV_CHUNKS, 0); in cf_h2_ctx_init()
165 Curl_bufq_initp(&ctx->outbufq, &ctx->stream_bufcp, H2_NW_SEND_CHUNKS, 0); in cf_h2_ctx_init()
166 Curl_dyn_init(&ctx->scratch, CURL_MAX_HTTP_HEADER); in cf_h2_ctx_init()
167 Curl_hash_offt_init(&ctx->streams, 63, h2_stream_hash_free); in cf_h2_ctx_init()
168 ctx->remote_max_sid = 2147483647; in cf_h2_ctx_init()
169 ctx->via_h1_upgrade = via_h1_upgrade; in cf_h2_ctx_init()
170 ctx->initialized = TRUE; in cf_h2_ctx_init()
173 static void cf_h2_ctx_free(struct cf_h2_ctx *ctx) in cf_h2_ctx_free() argument
175 if(ctx && ctx->initialized) { in cf_h2_ctx_free()
176 Curl_bufq_free(&ctx->inbufq); in cf_h2_ctx_free()
177 Curl_bufq_free(&ctx->outbufq); in cf_h2_ctx_free()
178 Curl_bufcp_free(&ctx->stream_bufcp); in cf_h2_ctx_free()
179 Curl_dyn_free(&ctx->scratch); in cf_h2_ctx_free()
180 Curl_hash_clean(&ctx->streams); in cf_h2_ctx_free()
181 Curl_hash_destroy(&ctx->streams); in cf_h2_ctx_free()
182 memset(ctx, 0, sizeof(*ctx)); in cf_h2_ctx_free()
184 free(ctx); in cf_h2_ctx_free()
187 static void cf_h2_ctx_close(struct cf_h2_ctx *ctx) in cf_h2_ctx_close() argument
189 if(ctx->h2) { in cf_h2_ctx_close()
190 nghttp2_session_del(ctx->h2); in cf_h2_ctx_close()
226 #define H2_STREAM_CTX(ctx,data) ((struct h2_stream_ctx *)(\ argument
227 data? Curl_hash_offt_get(&(ctx)->streams, (data)->mid) : NULL))
229 static struct h2_stream_ctx *h2_stream_ctx_create(struct cf_h2_ctx *ctx) in h2_stream_ctx_create() argument
233 (void)ctx; in h2_stream_ctx_create()
239 Curl_bufq_initp(&stream->sendbuf, &ctx->stream_bufcp, in h2_stream_ctx_create()
298 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_update_local_win() local
305 ctx->h2, stream->id); in cf_h2_update_local_win()
307 rv = nghttp2_submit_window_update(ctx->h2, NGHTTP2_FLAG_NONE, in cf_h2_update_local_win()
319 rv = nghttp2_session_set_local_window_size(ctx->h2, NGHTTP2_FLAG_NONE, in cf_h2_update_local_win()
375 struct cf_h2_ctx *ctx = cf->ctx; in http2_data_setup() local
380 stream = H2_STREAM_CTX(ctx, data); in http2_data_setup()
386 stream = h2_stream_ctx_create(ctx); in http2_data_setup()
390 if(!Curl_hash_offt_set(&ctx->streams, data->mid, stream)) { in http2_data_setup()
401 struct cf_h2_ctx *ctx = cf->ctx; in http2_data_done() local
402 struct h2_stream_ctx *stream = H2_STREAM_CTX(ctx, data); in http2_data_done()
404 DEBUGASSERT(ctx); in http2_data_done()
405 if(!stream || !ctx->initialized) in http2_data_done()
408 if(ctx->h2) { in http2_data_done()
411 (void)nghttp2_session_set_stream_user_data(ctx->h2, stream->id, NULL); in http2_data_done()
419 nghttp2_submit_rst_stream(ctx->h2, NGHTTP2_FLAG_NONE, in http2_data_done()
425 nghttp2_session_send(ctx->h2); in http2_data_done()
428 Curl_hash_offt_remove(&ctx->streams, data->mid); in http2_data_done()
434 struct cf_h2_ctx *ctx = cf->ctx; in h2_client_new() local
450 rc = nghttp2_session_client_new3(&ctx->h2, cbs, cf, o, &mem); in h2_client_new()
510 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_ctx_open() local
516 DEBUGASSERT(!ctx->h2); in cf_h2_ctx_open()
517 DEBUGASSERT(ctx->initialized); in cf_h2_ctx_open()
546 ctx->max_concurrent_streams = DEFAULT_MAX_CONCURRENT_STREAMS; in cf_h2_ctx_open()
548 if(ctx->via_h1_upgrade) { in cf_h2_ctx_open()
568 rc = nghttp2_session_upgrade2(ctx->h2, binsettings, (size_t)binlen, in cf_h2_ctx_open()
578 rc = nghttp2_session_set_stream_user_data(ctx->h2, stream->id, in cf_h2_ctx_open()
592 rc = nghttp2_submit_settings(ctx->h2, NGHTTP2_FLAG_NONE, in cf_h2_ctx_open()
602 rc = nghttp2_session_set_local_window_size(ctx->h2, NGHTTP2_FLAG_NONE, 0, in cf_h2_ctx_open()
614 ctx->via_h1_upgrade ? " (via h1 upgrade)" : ""); in cf_h2_ctx_open()
625 static int should_close_session(struct cf_h2_ctx *ctx) in should_close_session() argument
627 return ctx->drain_total == 0 && !nghttp2_session_want_read(ctx->h2) && in should_close_session()
628 !nghttp2_session_want_write(ctx->h2); in should_close_session()
640 struct cf_h2_ctx *ctx = cf->ctx; in h2_process_pending_input() local
645 while(Curl_bufq_peek(&ctx->inbufq, &buf, &blen)) { in h2_process_pending_input()
647 rv = nghttp2_session_mem_recv(ctx->h2, (const uint8_t *)buf, blen); in h2_process_pending_input()
655 Curl_bufq_skip(&ctx->inbufq, (size_t)rv); in h2_process_pending_input()
656 if(Curl_bufq_is_empty(&ctx->inbufq)) { in h2_process_pending_input()
661 "in connection buffer", Curl_bufq_len(&ctx->inbufq)); in h2_process_pending_input()
665 if(nghttp2_session_check_request_allowed(ctx->h2) == 0) { in h2_process_pending_input()
686 struct cf_h2_ctx *ctx = cf->ctx; in http2_connisalive() local
701 nread = Curl_bufq_slurp(&ctx->inbufq, nw_in_reader, cf, &result); in http2_connisalive()
709 alive = !should_close_session(ctx); in http2_connisalive()
724 struct cf_h2_ctx *ctx = cf->ctx; in http2_send_ping() local
727 rc = nghttp2_submit_ping(ctx->h2, 0, ZERO_NULL); in http2_send_ping()
734 rc = nghttp2_session_send(ctx->h2); in http2_send_ping()
755 struct cf_h2_ctx *ctx = cf->ctx; in nw_out_flush() local
760 if(Curl_bufq_is_empty(&ctx->outbufq)) in nw_out_flush()
763 nwritten = Curl_bufq_pass(&ctx->outbufq, nw_out_writer, cf, &result); in nw_out_flush()
767 Curl_bufq_len(&ctx->outbufq)); in nw_out_flush()
768 ctx->nw_out_blocked = 1; in nw_out_flush()
772 return Curl_bufq_is_empty(&ctx->outbufq) ? CURLE_OK : CURLE_AGAIN; in nw_out_flush()
785 struct cf_h2_ctx *ctx = cf->ctx; in send_callback() local
795 nwritten = Curl_bufq_write(&ctx->outbufq, buf, blen, &result); in send_callback()
797 nwritten = Curl_bufq_write_pass(&ctx->outbufq, buf, blen, in send_callback()
801 ctx->nw_out_blocked = 1; in send_callback()
809 ctx->nw_out_blocked = 1; in send_callback()
951 struct cf_h2_ctx *ctx = cf->ctx; in push_promise() local
973 stream = H2_STREAM_CTX(ctx, data); in push_promise()
1031 rv = nghttp2_session_set_stream_user_data(ctx->h2, in push_promise()
1043 if(newstream->id > ctx->local_max_sid) in push_promise()
1044 ctx->local_max_sid = newstream->id; in push_promise()
1084 struct cf_h2_ctx *ctx = cf->ctx; in h2_xfer_write_resp() local
1088 nghttp2_submit_rst_stream(ctx->h2, 0, stream->id, in h2_xfer_write_resp()
1097 struct cf_h2_ctx *ctx = cf->ctx; in on_stream_frame() local
1098 struct h2_stream_ctx *stream = H2_STREAM_CTX(ctx, data); in on_stream_frame()
1112 ctx->h2, stream->id), in on_stream_frame()
1114 ctx->h2, stream->id)); in on_stream_frame()
1117 rv = nghttp2_submit_rst_stream(ctx->h2, NGHTTP2_FLAG_NONE, in on_stream_frame()
1155 rv = nghttp2_submit_rst_stream(ctx->h2, NGHTTP2_FLAG_NONE, in on_stream_frame()
1181 rv = nghttp2_session_resume_data(ctx->h2, stream->id); in on_stream_frame()
1199 nghttp2_submit_rst_stream(ctx->h2, NGHTTP2_FLAG_NONE, in on_stream_frame()
1303 struct cf_h2_ctx *ctx = cf->ctx; in on_frame_recv() local
1324 uint32_t max_conn = ctx->max_concurrent_streams; in on_frame_recv()
1325 ctx->max_concurrent_streams = nghttp2_session_get_remote_settings( in on_frame_recv()
1327 ctx->enable_push = nghttp2_session_get_remote_settings( in on_frame_recv()
1330 ctx->max_concurrent_streams); in on_frame_recv()
1332 ctx->enable_push ? "TRUE" : "false"); in on_frame_recv()
1333 if(data && max_conn != ctx->max_concurrent_streams) { in on_frame_recv()
1336 ctx->max_concurrent_streams); in on_frame_recv()
1345 struct h2_stream_ctx *stream = H2_STREAM_CTX(ctx, data); in on_frame_recv()
1353 ctx->rcvd_goaway = TRUE; in on_frame_recv()
1354 ctx->goaway_error = frame->goaway.error_code; in on_frame_recv()
1355 ctx->remote_max_sid = frame->goaway.last_stream_id; in on_frame_recv()
1358 ctx->goaway_error, ctx->remote_max_sid); in on_frame_recv()
1382 struct cf_h2_ctx *ctx = cf->ctx; in on_data_chunk_recv() local
1403 stream = H2_STREAM_CTX(ctx, data_s); in on_data_chunk_recv()
1409 nghttp2_session_consume(ctx->h2, stream_id, len); in on_data_chunk_recv()
1418 struct cf_h2_ctx *ctx = cf->ctx; in on_stream_close() local
1442 stream = H2_STREAM_CTX(ctx, data_s); in on_stream_close()
1476 struct cf_h2_ctx *ctx = cf->ctx; in on_begin_headers() local
1490 stream = H2_STREAM_CTX(ctx, data_s); in on_begin_headers()
1506 struct cf_h2_ctx *ctx = cf->ctx; in on_header() local
1522 stream = H2_STREAM_CTX(ctx, data_s); in on_header()
1616 Curl_dyn_reset(&ctx->scratch); in on_header()
1617 result = Curl_dyn_addn(&ctx->scratch, STRCONST("HTTP/2 ")); in on_header()
1619 result = Curl_dyn_addn(&ctx->scratch, value, valuelen); in on_header()
1621 result = Curl_dyn_addn(&ctx->scratch, STRCONST(" \r\n")); in on_header()
1623 h2_xfer_write_resp_hd(cf, data_s, stream, Curl_dyn_ptr(&ctx->scratch), in on_header()
1624 Curl_dyn_len(&ctx->scratch), FALSE); in on_header()
1639 Curl_dyn_reset(&ctx->scratch); in on_header()
1640 result = Curl_dyn_addn(&ctx->scratch, (const char *)name, namelen); in on_header()
1642 result = Curl_dyn_addn(&ctx->scratch, STRCONST(": ")); in on_header()
1644 result = Curl_dyn_addn(&ctx->scratch, (const char *)value, valuelen); in on_header()
1646 result = Curl_dyn_addn(&ctx->scratch, STRCONST("\r\n")); in on_header()
1648 h2_xfer_write_resp_hd(cf, data_s, stream, Curl_dyn_ptr(&ctx->scratch), in on_header()
1649 Curl_dyn_len(&ctx->scratch), FALSE); in on_header()
1670 struct cf_h2_ctx *ctx = cf->ctx; in req_body_read_callback() local
1689 stream = H2_STREAM_CTX(ctx, data_s); in req_body_read_callback()
1867 static void h2_pri_spec(struct cf_h2_ctx *ctx, in h2_pri_spec() argument
1872 struct h2_stream_ctx *depstream = H2_STREAM_CTX(ctx, prio->parent); in h2_pri_spec()
1889 struct cf_h2_ctx *ctx = cf->ctx; in h2_progress_egress() local
1890 struct h2_stream_ctx *stream = H2_STREAM_CTX(ctx, data); in h2_progress_egress()
1900 h2_pri_spec(ctx, data, &pri_spec); in h2_progress_egress()
1903 rv = nghttp2_submit_priority(ctx->h2, NGHTTP2_FLAG_NONE, in h2_progress_egress()
1909 ctx->nw_out_blocked = 0; in h2_progress_egress()
1910 while(!rv && !ctx->nw_out_blocked && nghttp2_session_want_write(ctx->h2)) in h2_progress_egress()
1911 rv = nghttp2_session_send(ctx->h2); in h2_progress_egress()
1931 struct cf_h2_ctx *ctx = cf->ctx; in stream_recv() local
1946 (ctx->conn_closed && Curl_bufq_is_empty(&ctx->inbufq)) || in stream_recv()
1947 (ctx->rcvd_goaway && ctx->remote_max_sid < stream->id)) { in stream_recv()
1963 struct cf_h2_ctx *ctx = cf->ctx; in h2_progress_ingress() local
1969 if(!Curl_bufq_is_empty(&ctx->inbufq)) { in h2_progress_ingress()
1971 Curl_bufq_len(&ctx->inbufq)); in h2_progress_ingress()
1979 while(!ctx->conn_closed && Curl_bufq_is_empty(&ctx->inbufq)) { in h2_progress_ingress()
1980 stream = H2_STREAM_CTX(ctx, data); in h2_progress_ingress()
1991 nread = Curl_bufq_sipn(&ctx->inbufq, 0, nw_in_reader, cf, &result); in h2_progress_ingress()
2002 ctx->conn_closed = TRUE; in h2_progress_ingress()
2014 Curl_bufq_len(&ctx->inbufq)); in h2_progress_ingress()
2017 if(ctx->conn_closed && Curl_bufq_is_empty(&ctx->inbufq)) { in h2_progress_ingress()
2028 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_recv() local
2029 struct h2_stream_ctx *stream = H2_STREAM_CTX(ctx, data); in cf_h2_recv()
2073 nghttp2_session_consume(ctx->h2, stream->id, data_consumed); in cf_h2_recv()
2100 ctx->h2, stream->id), in cf_h2_recv()
2102 ctx->h2, stream->id), in cf_h2_recv()
2103 nghttp2_session_get_local_window_size(ctx->h2), in cf_h2_recv()
2116 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_body_send() local
2148 int rv = nghttp2_session_resume_data(ctx->h2, stream->id); in cf_h2_body_send()
2162 struct cf_h2_ctx *ctx = cf->ctx; in h2_submit() local
2205 h2_pri_spec(ctx, data, &pri_spec); in h2_submit()
2206 if(!nghttp2_session_check_request_allowed(ctx->h2)) in h2_submit()
2216 stream_id = nghttp2_submit_request(ctx->h2, &pri_spec, nva, nheader, in h2_submit()
2220 stream_id = nghttp2_submit_request(ctx->h2, &pri_spec, nva, nheader, in h2_submit()
2284 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_send() local
2285 struct h2_stream_ctx *stream = H2_STREAM_CTX(ctx, data); in cf_h2_send()
2337 if(should_close_session(ctx)) { in cf_h2_send()
2358 ctx->h2, stream->id), in cf_h2_send()
2359 nghttp2_session_get_remote_window_size(ctx->h2), in cf_h2_send()
2361 Curl_bufq_len(&ctx->outbufq)); in cf_h2_send()
2367 nghttp2_session_get_remote_window_size(ctx->h2), in cf_h2_send()
2368 Curl_bufq_len(&ctx->outbufq)); in cf_h2_send()
2377 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_flush() local
2378 struct h2_stream_ctx *stream = H2_STREAM_CTX(ctx, data); in cf_h2_flush()
2385 int rv = nghttp2_session_resume_data(ctx->h2, stream->id); in cf_h2_flush()
2401 ctx->h2, stream->id), in cf_h2_flush()
2402 nghttp2_session_get_remote_window_size(ctx->h2), in cf_h2_flush()
2404 Curl_bufq_len(&ctx->outbufq)); in cf_h2_flush()
2409 result, nghttp2_session_get_remote_window_size(ctx->h2), in cf_h2_flush()
2410 Curl_bufq_len(&ctx->outbufq)); in cf_h2_flush()
2420 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_adjust_pollset() local
2425 if(!ctx->h2) in cf_h2_adjust_pollset()
2431 struct h2_stream_ctx *stream = H2_STREAM_CTX(ctx, data); in cf_h2_adjust_pollset()
2435 c_exhaust = want_send && !nghttp2_session_get_remote_window_size(ctx->h2); in cf_h2_adjust_pollset()
2437 !nghttp2_session_get_stream_remote_window_size(ctx->h2, in cf_h2_adjust_pollset()
2441 (!c_exhaust && nghttp2_session_want_write(ctx->h2)) || in cf_h2_adjust_pollset()
2442 !Curl_bufq_is_empty(&ctx->outbufq); in cf_h2_adjust_pollset()
2447 else if(ctx->sent_goaway && !cf->shutdown) { in cf_h2_adjust_pollset()
2450 want_send = nghttp2_session_want_write(ctx->h2) || in cf_h2_adjust_pollset()
2451 !Curl_bufq_is_empty(&ctx->outbufq); in cf_h2_adjust_pollset()
2452 want_recv = nghttp2_session_want_read(ctx->h2); in cf_h2_adjust_pollset()
2462 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_connect() local
2482 DEBUGASSERT(ctx->initialized); in cf_h2_connect()
2483 if(!ctx->h2) { in cf_h2_connect()
2516 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_close() local
2518 if(ctx) { in cf_h2_close()
2522 cf_h2_ctx_close(ctx); in cf_h2_close()
2532 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_destroy() local
2535 if(ctx) { in cf_h2_destroy()
2536 cf_h2_ctx_free(ctx); in cf_h2_destroy()
2537 cf->ctx = NULL; in cf_h2_destroy()
2544 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_shutdown() local
2549 if(!cf->connected || !ctx->h2 || cf->shutdown || ctx->conn_closed) { in cf_h2_shutdown()
2556 if(!ctx->sent_goaway) { in cf_h2_shutdown()
2557 rv = nghttp2_submit_goaway(ctx->h2, NGHTTP2_FLAG_NONE, in cf_h2_shutdown()
2558 ctx->local_max_sid, 0, in cf_h2_shutdown()
2567 ctx->sent_goaway = TRUE; in cf_h2_shutdown()
2571 if(nghttp2_session_want_write(ctx->h2) || in cf_h2_shutdown()
2572 !Curl_bufq_is_empty(&ctx->outbufq)) in cf_h2_shutdown()
2574 if(!result && nghttp2_session_want_read(ctx->h2)) in cf_h2_shutdown()
2580 *done = (ctx->conn_closed || in cf_h2_shutdown()
2581 (!result && !nghttp2_session_want_write(ctx->h2) && in cf_h2_shutdown()
2582 !nghttp2_session_want_read(ctx->h2) && in cf_h2_shutdown()
2583 Curl_bufq_is_empty(&ctx->outbufq))); in cf_h2_shutdown()
2595 struct cf_h2_ctx *ctx = cf->ctx; in http2_data_pause() local
2596 struct h2_stream_ctx *stream = H2_STREAM_CTX(ctx, data); in http2_data_pause()
2599 if(ctx && ctx->h2 && stream) { in http2_data_pause()
2657 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_data_pending() local
2658 struct h2_stream_ctx *stream = H2_STREAM_CTX(ctx, data); in cf_h2_data_pending()
2660 if(ctx && (!Curl_bufq_is_empty(&ctx->inbufq) in cf_h2_data_pending()
2670 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_is_alive() local
2675 result = (ctx && ctx->h2 && http2_connisalive(cf, data, input_pending)); in cf_h2_is_alive()
2698 struct cf_h2_ctx *ctx = cf->ctx; in cf_h2_query() local
2707 if(nghttp2_session_check_request_allowed(ctx->h2) == 0) { in cf_h2_query()
2712 effective_max = ctx->max_concurrent_streams; in cf_h2_query()
2718 struct h2_stream_ctx *stream = H2_STREAM_CTX(ctx, data); in cf_h2_query()
2723 struct h2_stream_ctx *stream = H2_STREAM_CTX(ctx, data); in cf_h2_query()
2724 if(!Curl_bufq_is_empty(&ctx->outbufq) || in cf_h2_query()
2765 struct cf_h2_ctx *ctx; in http2_cfilter_add() local
2769 ctx = calloc(1, sizeof(*ctx)); in http2_cfilter_add()
2770 if(!ctx) in http2_cfilter_add()
2772 cf_h2_ctx_init(ctx, via_h1_upgrade); in http2_cfilter_add()
2774 result = Curl_cf_create(&cf, &Curl_cft_nghttp2, ctx); in http2_cfilter_add()
2778 ctx = NULL; in http2_cfilter_add()
2783 cf_h2_ctx_free(ctx); in http2_cfilter_add()
2793 struct cf_h2_ctx *ctx; in http2_cfilter_insert_after() local
2797 ctx = calloc(1, sizeof(*ctx)); in http2_cfilter_insert_after()
2798 if(!ctx) in http2_cfilter_insert_after()
2800 cf_h2_ctx_init(ctx, via_h1_upgrade); in http2_cfilter_insert_after()
2802 result = Curl_cf_create(&cf_h2, &Curl_cft_nghttp2, ctx); in http2_cfilter_insert_after()
2806 ctx = NULL; in http2_cfilter_insert_after()
2811 cf_h2_ctx_free(ctx); in http2_cfilter_insert_after()
2907 struct cf_h2_ctx *ctx; in Curl_http2_upgrade() local
2919 ctx = cf->ctx; in Curl_http2_upgrade()
2927 copied = Curl_bufq_write(&ctx->inbufq, in Curl_http2_upgrade()