curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: Fwd: Multi-uv.c with custom class

From: doa379 via curl-library <curl-library_at_cool.haxx.se>
Date: Wed, 20 Sep 2017 15:03:23 +0100

I don't know about you but libuv is a more appropriate library to bring
features such as asynchronisity to the C language. C++11 has many such
features as well as ease of implementing an event loop already built
natively. From my experience even in the case of implementing an aync
app in C there are have been some unknowns and mysteries in the library
which are still have me dumbfounded to date in my own use case.

I'm not entirely surprised if this library malfunctions in a fringe case
such as yours.

I recently implemented a C++ app and I have resorted to using the more
standard features of libcurl (via easy and multi handles). I'm glad it
works. Also there are other OO network libraries you could consider,
Poco for example. I have liked libcurl and so have stuck with it.

I would guess you might want to send the data as a struct rather than a
class to libuv. And/or secondly you could consider inverting the scope
of your class in order to encapsulate libuv rather than sending a
pointer to the class to libuv.

On 20/09/17 14:33, brano199 . via curl-library wrote:
> Ok i will try to ask more concretely. Your example works really well
> when loop, handle and timeout are defined as global variables. What i
> would like to do is have a class which has these variables as members.
> What i was trying to do was to send that class into socket action and
> timer as follows
>
> curl_multi_setopt(socket_wrapper.multi_handle, CURLMOPT_SOCKETDATA,
> &socket_wrapper);
> curl_multi_setopt(socket_wrapper.multi_handle,
> CURLMOPT_SOCKETFUNCTION, handle_socket);
> curl_multi_setopt(socket_wrapper.multi_handle, CURLMOPT_TIMERDATA,
> &socket_wrapper);
> curl_multi_setopt(socket_wrapper.multi_handle,
> CURLMOPT_TIMERFUNCTION, start_timeout);
>
>
> In handle_socket i have modified your original example just by casting
> the pointer to my class and inside create_curl_context function i
> remembered context in my class and instead of doing
>
> context->poll_handle.data = context; i have done
> context->poll_handle.data = socket_wrapper;
>
> to remember my whole class instead of just context.
>
> So the question is more like that i don' t know how to pass context and
> which are all of the necessary informations that need to be passed along
> those functions to get it working,because apparently my code isn' t
> working and i don' t even know where,i have tried debugging it.
>
> 2017-09-19 14:46 GMT+02:00 Daniel Stenberg <daniel_at_haxx.se
> <mailto:daniel_at_haxx.se>>:
>
> On Sun, 17 Sep 2017, brano199 . via curl-library wrote:
>
> i am C++ developer and i am having trouble modifying this
> example to use custom class
> https://curl.haxx.se/libcurl/c/multi-uv.html
> <https://curl.haxx.se/libcurl/c/multi-uv.html>. Everytime i am
> gettign stack overflow and i can' t really figure out what am i
> doing wrong. Would you be so kind and take a look at my code?
>
>
> That's a pretty big and wide question and I'd say a bit overwhelming
> to take on.
>
> Any chance you can isolate your problems and ask more specific
> qeustions?
>
> --
>
>  / daniel.haxx.se <http://daniel.haxx.se>
>
>
>
>
>
> -------------------------------------------------------------------
> Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
> Etiquette: https://curl.haxx.se/mail/etiquette.html
>
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-09-20