W dniu 2022-06-17 13:39, Daniel Stenberg via curl-library napisaƂ(a):
Hello,

Last year when we brainstormed different takes on a WebSockets idea,
we landed on a separate ws callback for writing data, similar to the
regular CURLOPT_WRITEFUNCTION. [*]

A separate callback, because it needs to provide some additional data
that the plain callback doesn't receive.

Now when I've started working on implementing websockets, I'm having
second thoughts on that design but I can't decide on what's a better
way. So I'm here to see if someone else can fix this for me! =)

I would like to provide websockets data with the CURLOPT_WRITEFUNCTION
callback as well. But how would libcurl provide the additional
necessary metadata?

My initial thought was to provide a special websocket function that
only can be used from within the callback that would provide the extra
information (type of data, opcode, and if the FIN bit is set or not
etc). Like maybe
'curl_ws_metadata()'.

This is what makes me hesitate on this idea:

This new function would need to get the easy handle as an argument, so
that it can find and return the correct information, but the
CURLOPT_WRITEFUNCTION does not pass in the easy handle! So in order to
use this function within the callback, it would require that the
callback on its own design gets the easy handle passed into it via the
CURLOPT_WRITEDATA option in some manner.

Would that be a sensible requirement or would be asking too much of an
application?

Or can we come up with a better way?

[*] = https://github.com/curl/curl/wiki/WebSockets

Hi,
For me this new proposal is fine. In my apps I always pass pointer to some structure or class to CURLOPT_WRITEDATA. and this structure/class contains curl handle in addition to other data.

I can guess that apps written by others either pass pointer to struct/class to CURLOPT_WRITEDATA, pass index from some array to CURLOPT_WRITEDATA, or use single curl handle in whole app, which is stored globally or in other well-known place. I do not see any special issue in any of these approaches.

Make sure to properly document it with example how to use this. Full info should be in docs for curl_ws_metadata function, plus some new note in existing docs for CURLOPT_WRITEFUNCTION and CURLOPT_WRITEDATA that WebSockets have extra requirement.

--
Regards,
Daniel
--
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html

Reply via email to