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.

About a websockets write callback

From: Daniel Stenberg via curl-library <>
Date: Fri, 17 Jun 2022 13:39:00 +0200 (CEST)


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

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

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

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

Or can we come up with a better way?

[*] =

  | Commercial curl support up to 24x7 is available!
  | Private help, bug fixes, support, ports, new features
Received on 2022-06-17