1

So, I'm playing with callbacks in GNUTLS.

I want to pass my function, handleSNI to a function, but I also want to pass on some other important arguments as well(to handleSNI when it is called).

I could just do them outside the functions in global variables, but that isn't thread safe.

Is it possible? If not, how can one accomplish this?

JavaProphet
  • 931
  • 14
  • 29

1 Answers1

1

GnuTLS supports user defined arguments in callbacks. For the push and pull function you set them via gnutls_transport_set_ptr. You pass a pointer to a struct containing your data and use that in your callback.

On a more general level the answer is: If your library doesn't support user defined parameters, you are out of luck. In C there is no way to cheat an extra parameter in. If you ever find such a library, do your self a favor and don't use it. And if there is no alternative you could use threadsafe containers or thread local storage. But it is really ugly.

Cookie
  • 26
  • 2