C SDK - Socket API vs libuv

I had someone ask me this question in email. I think it is broadly applicable to the openziti project in general so I translated it here:

I am trying to integrate ziti SDK into fluent-bit which is written C and I am looking at ziti c language SDK to do so. Do you have any documents that support the same. Also, I see that all the sdk functions are using libuv and seems like ziti c SDK is tightly coupled with libuv where as fluent bit uses direct socket api. Any suggestions on how to go about this?

I'll reply on this thread

Right now we don’t have a tremendous amount of doc around ‘how to’ with the Ziti SDKs. We provide some samples illustrating how to use it but that’s generally all we have at this time. We keep trying to build out that documentation but it’s not there yet.

the ziti C SDK is definitely tied tightly to libuv’s asynchronous API model. If fluent is expecting to make a socket of their own and use that API it’s probably going to be hard to zitify it.

I expect you’re using https://fluentbit.io/, can you point out what function you were looking at?

I’ll send your question to some others internally and ask them to look at this post and comment if they can add anything

Hi @TheLumberjack ,
Yes, I was referring to https://fluentbit.io/ and here is the function I am trying to zitify fluent-bit/flb_network.c at a626de2d8bf6701293d2a722ac88df3e982ed052 · fluent/fluent-bit · GitHub

Some observations after poking around in fluent-bit code:

  • fluent-bit is doing async io with mk_event_loop and with co_threads
  • mk_event library seem to be more low-level than libuv – operates at file descriptor level
  • flb_upstream seems like better injection point for ziti connection – flb_upstream could be either plain socket or ziti_connection
  • another thread is need to run uv_loop
  • some coordination code has to be implemented in order for ziti_connection to participate in mk_event_loop: create a file descriptor (probably pipe) to trigger read events from ziti_read_cb()