curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Support HTTP2 Goaway Frame callback for curl multi

From: Ray Satiro via curl-library <curl-library_at_lists.haxx.se>
Date: Fri, 5 Jan 2024 02:24:52 -0500

On 1/4/2024 10:45 PM, Cao Duc Quan via curl-library wrote:
> I am working on a small project where I need a callback from CURM when
> it receives the GOAWAY frame. I prepared a patch as follows and could
> get the callback for GOAWAY
>
> diff --git a/include/curl/multi.h b/include/curl/multi.h
> index e79b48ff3..c1b5adede 100644
> --- a/include/curl/multi.h
> +++ b/include/curl/multi.h
> _at__at_ -348,6 +348,12 @@ curl_multi_socket_all(CURLM *multi_handle, int
> *running_handles);
>  CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle,
>                                           long *milliseconds);
>
> +/*
> + * This macro help client know if they could install GOAWAY callback
> to this curl version.
> + * This is a temporary solution before the patch is merged to cURL
> mainline.
> + */
> +#define CURL_HAS_GOAWAY_CALLBACK 1
> +
>  typedef enum {
>    /* This is the socket callback function pointer */
>    CURLOPT(CURLMOPT_SOCKETFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 1),
> _at__at_ -399,6 +405,12 @@ typedef enum {
>    /* maximum number of concurrent streams to support on a connection */
>    CURLOPT(CURLMOPT_MAX_CONCURRENT_STREAMS, CURLOPTTYPE_LONG, 16),
>
> +  /* This is the goaway callback function pointer */
> +  CURLOPT(CURLMOPT_GOAWAY_CALLBACK, CURLOPTTYPE_FUNCTIONPOINT, 17),
> +
> +  /* This is the argument passed to the goaway callback */
> +  CURLOPT(CURLMOPT_GOAWAY_DATA, CURLOPTTYPE_OBJECTPOINT, 18),
> +
>    CURLMOPT_LASTENTRY /* the last unused */
>  } CURLMoption;
>
> _at__at_ -464,6 +476,19 _at__at_ typedef int (*curl_push_callback)(CURL *parent,
>                                    struct curl_pushheaders *headers,
>                                    void *userp);
>
> +/*
> + * Name: curl_goaway_callback
> + *
> + * Desc: This callback gets called when HTTP2 connection received
> + *       GOAWAY frame from peer. The Application may interest on this
> + *       event to trigger clean up functions or prepare new fresh
> + *       connection.
> + *
> + * Returns: None
> + */
> +typedef void (*curl_goaway_callback)(unsigned int error_code,
> +                                  int last_stream_id,
> +                                  void *userp);
>  #ifdef __cplusplus
>  } /* end of extern "C" */
>  #endif
> diff --git a/lib/http2.c b/lib/http2.c
> index c8b059498..6e28561f0 100644
> --- a/lib/http2.c
> +++ b/lib/http2.c
> _at__at_ -1251,6 +1251,13 _at_@ static int on_frame_recv(nghttp2_session
> *session, const nghttp2_frame *frame,
>          infof(data, "received GOAWAY, error=%d, last_stream=%u",
>                      ctx->goaway_error, ctx->last_stream_id);
>          Curl_multi_connchanged(data->multi);
> +        if(data->multi->goaway_cb) {
> +          Curl_set_in_callback(data, true);
> +          data->multi->goaway_cb(ctx->goaway_error,
> +                                 ctx->last_stream_id,
> + data->multi->goaway_userp);
> +          Curl_set_in_callback(data, false);
> +        }
>        }
>        break;
>      default:
>
>
> I would like to ask if there is an obvious issue with the patch. If
> not, could anyone guide me through any procedure I need to follow to
> get it in the cURL in github?


I won't land this. It sounds a lot like curl/curl#4839 [1]. Do you
really need it in curl or is there some way your application is working
that could be improved?


[1]: https://github.com/curl/curl/issues/4839

-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2024-01-05