Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C][Client]Support data callback function #7467

Merged
merged 1 commit into from
Sep 25, 2020

Conversation

ityuhui
Copy link
Contributor

@ityuhui ityuhui commented Sep 21, 2020

There is a special API design:
When the client issues a http request, http server will block the request ( does not return to client ), and write some data to stream to client continuously.
e.g.
In kubernetes, when client issues a watch request, kube-apiserver will block this request, but write the watch event data to the stream to client once there is new event such as pod creation/deletion. Client needs to read and handle these event data.

But for now, c generator does not support this mode because apiClient_invoke and writeDataCallback have no chance to access the raw data if the request is blocking.

This PR adds a data_callback_func to writeDataCallback, if it is not NULL, it will be called to access the data received. By this means, user can inject a data_callback_func to handle when the request is blocking.

size_t writeDataCallback(void *buffer, size_t size, size_t nmemb, void *userp) {
    ...
    if (apiClient->data_callback_func) {
        apiClient->data_callback_func(&apiClient->dataReceived, &apiClient->dataReceivedLen);
    }
    ...
}

This change does not impact current request logic because apiClient->data_callback_func = NULL by default.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@wing328 @zhemant @michelealbano

@auto-labeler
Copy link

auto-labeler bot commented Sep 21, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@wing328
Copy link
Member

wing328 commented Sep 25, 2020

CircleCI failure already fixed in the master

@wing328 wing328 merged commit f608803 into OpenAPITools:master Sep 25, 2020
@ityuhui
Copy link
Contributor Author

ityuhui commented Sep 26, 2020

Thank you @wing328

@ityuhui ityuhui deleted the yhdatacallback branch September 26, 2020 04:09
jimschubert added a commit to david1601/openapi-generator that referenced this pull request Sep 28, 2020
…or-extension-x-spring-paginated

* master: (29 commits)
  [Core, HTML2] Rendered docs are incomplete (OpenAPITools#7510)
  [C][Client]Support data callback function (OpenAPITools#7467)
  [typescript-axios] replace optional chaining (OpenAPITools#7476)
  [typescript-axios] fix refining `query` (OpenAPITools#7475)
  [powershell] Updated the Api doc with httpsiging script snippet. (OpenAPITools#7499)
  [go][client] Fix API docs example generation (OpenAPITools#7489)
  [ci][test] Fix samples (OpenAPITools#7509)
  [bug][Java] Honor instantiationMap for default values for array, map, set (OpenAPITools#4982)
  Fix stringifying of ~= (OpenAPITools#7460)
  minor formatting change (OpenAPITools#7503)
  [ruby] Fix generation when generateAliasAsModel is enabled (OpenAPITools#7419)
  [sonar][ci] Fixes some new recommended "bug" fixes found via Sonar (OpenAPITools#7508)
  Add option to set recursion limit (OpenAPITools#7491)
  regenerate java pkmst petstore samples (OpenAPITools#7502)
  fix issue without http signature auth (OpenAPITools#7504)
  [ruby] Support for per-operation servers (OpenAPITools#7415)
  Add a link to react native tutorial (OpenAPITools#7505)
  update of Objective-C model-body.mustache to support discriminator.mappedModels (OpenAPITools#7471)
  update samples
  [ci] Sonar bug fixes (OpenAPITools#7497)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants