https://kotlinlang.org logo
Title
v

Venkat

05/22/2023, 6:08 AM
Does Kotlin native have support for any IPC mechanism in the Linux platform? Like D-Bus. I can see that ktor has a socket but I'm just looking is there any high level IPC that exists like D-Bus, Grpc or something else.
e

elizarov

05/22/2023, 7:48 AM
You can use all the Posix directly.
v

Venkat

05/22/2023, 7:50 AM
You mean binding POSIX D-Bus C API to Kotlin native? Or the bindings already available via platform libs?
e

elizarov

05/22/2023, 7:53 AM
I have not seen hand-crafted Kotlin bindings, but C APIs like D-Bus should be directly usable from Kotlin/Native via cinterop, just like all other C libraries.
v

Venkat

05/22/2023, 7:58 AM
Alright, just one last question. If I create a Kotlin native lib and it is going to be used via C then the Kotlin lib interface should not contain any suspend function as API isn't it? Because I see that suspend functions are exposed to objective-C via some Callback Handler, so is there any magic :magic_wand: similar to that for "C" 😁?
e

elizarov

05/22/2023, 7:59 AM
Yes, for C APIs you should provide some C-style async (via completion callbacks maybe?)
v

Venkat

05/22/2023, 8:01 AM
Is there any example for this somewhere? If not I'll try myself later 🙂 Thanks for your comments
e

elizarov

05/22/2023, 8:02 AM
Cannot think of any. It really depends on the style of C ecosystem you are planning to interact with.
v

Venkat

05/22/2023, 8:04 AM
But in any case, if I want to expose Kotlin native API to "C" then I need to auto generate "C" headers for those Kotlin APIs, but the auto generator will simply ignore the API if it's marked as suspend right?
a

Adam S

05/22/2023, 8:30 AM
I suspect that suspend functions are not ignored, but try giving it a go and report back :) https://kotlinlang.org/docs/native-dynamic-libraries.html At least for Objective-C they are generated https://kotlinlang.org/docs/native-objc-interop.html#suspending-functions
v

Venkat

05/23/2023, 4:24 PM
Yep! My guess was correct. I just made the functions in these examples ( https://kotlinlang.org/docs/native-dynamic-libraries.html )as suspend and the generator just ignores those functions. Now I'm thinking of adding those functions with callbacks and trying to communicate from C 🤔