kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
144 stars 46 forks source link

websockets in multi-thread #72

Closed clearday4 closed 2 years ago

clearday4 commented 3 years ago

Could you put *g_lws_context and g_interrupted into the wsclient_t structure?

typedef struct wsclient_t {
    char *server_address;
    int server_port;
    char *path;
    char *data_to_send;
    long data_to_send_len;
    void *data_received;
    long data_received_len;
    data_callback_func data_callback_func;
    int log_mask;
    lws_sorted_usec_list_t sul; /* schedule connection retry */
    struct lws *wsi;        /* related wsi if any */
    uint16_t retry_count;   /* count of consequetive retries */
    sslConfig_t *ssl_config;
    list_t *api_keys;

    struct lws_context *context;
    bool   interrupted;

} wsclient_t;
ityuhui commented 3 years ago

I will try some times later.

Have you tried this ? Is multi-threading OK just adding the two data to wsclient_t ?

clearday4 commented 3 years ago

I will try some times later.

Have you tried this ? Is multi-threading OK just adding the two data to wsclient_t ?

yes, it works. The important point is to use lws_context and interrupted separately for each api call.

ityuhui commented 3 years ago

The important point is to use lws_context and interrupted separately for each api call.

Do you have a sample code ?

Or could you please submit a PR to deliver this change ?

clearday4 commented 3 years ago

Use wsc->context instead of g_lws_context, and wsc->interrupted instead of g_interrupted.

wsc->context is created and destroyed in wsclient_run()

#ifdef  CONFIG_CP_MULTI_THREAD
    wsc->context = lws_create_context(&info);
    if (!wsc->context) {
        lwsl_err("%s: wsclient init failed.\n", __func__);
        return 1;
    }

    /* schedule the first client connection attempt to happen immediately */
    lws_sul_schedule(wsc->context, 0, &wsc->sul, connect_client, 1);
#else
    g_lws_context = lws_create_context(&info);
    if (!g_lws_context) {
        lwsl_err("%s: wsclient init failed.\n", __func__);
        return 1;
    }

    /* schedule the first client connection attempt to happen immediately */
    lws_sul_schedule(g_lws_context, 0, &wsc->sul, connect_client, 1);
#endif

...
...
...

#ifdef  CONFIG_CP_MULTI_THREAD
    lws_context_destroy(wsc->context);
    wsc->interrupted = false;
#else
    lws_context_destroy(g_lws_context);
    g_interrupted = false;
#endif
k8s-triage-robot commented 2 years ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

ityuhui commented 2 years ago

/remove-lifecycle stale

k8s-triage-robot commented 2 years ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

ityuhui commented 2 years ago

/remove-lifecycle stale

k8s-triage-robot commented 2 years ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 2 years ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot commented 2 years ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

k8s-ci-robot commented 2 years ago

@k8s-triage-robot: Closing this issue.

In response to [this](https://github.com/kubernetes-client/c/issues/72#issuecomment-1177235709): >The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. > >This bot triages issues and PRs according to the following rules: >- After 90d of inactivity, `lifecycle/stale` is applied >- After 30d of inactivity since `lifecycle/stale` was applied, `lifecycle/rotten` is applied >- After 30d of inactivity since `lifecycle/rotten` was applied, the issue is closed > >You can: >- Reopen this issue or PR with `/reopen` >- Mark this issue or PR as fresh with `/remove-lifecycle rotten` >- Offer to help out with [Issue Triage][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.