https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

aleksey.tomin

07/22/2020, 11:24 AM
Why
getnameinfo
function for macosX64 and linuxX64 target in
platform.posix
but for mingwX64 in
platform.windows
? It it a bug or feature?
a

Artyom Degtyarev [JB]

07/22/2020, 12:22 PM
This is an expectable difference, as this function is located in different headers:
ws2tcpip.h
for mingw_x64 target and
netdb.h
for macOS/Linux. The first header is defined as a part of
windows.def
, while the second can be found in
<osx|linux>/posix.def
. While it can be relocated to the mingw’s posix KLIB, one could say it is controversial decision.
a

aleksey.tomin

07/22/2020, 1:50 PM
I use “host” target - same as https://github.com/Kotlin/kotlinconf-spinner/tree/master/httpserver And I’ve added
getnameinfo
function to allow requests only from localhost. And now I can’t compile same code on Win and Mac. How can I do it? I can’t use 1.4-M3 because my app cann’t be compiled on this version.
a

Artyom Degtyarev [JB]

07/22/2020, 2:06 PM
Hmm, that could be a problem. Maybe this obstacle worth moving to more straightforward targeting, with separate source sets. If the signature is the same, one could try using expect/actual mechanism, typealiasing actual function to a platform-specific one.
a

aleksey.tomin

07/22/2020, 5:14 PM
expect typealias Addr
Modifier 'expect' is not applicable to 'typealias'
a

Artyom Degtyarev [JB]

07/22/2020, 5:22 PM
Sorry, I meant something like
expect fun getAddr
in the common code, with appropriate signature, and
actual typealias getAddr = platform.posix.getaddrinfo
a

aleksey.tomin

07/22/2020, 5:34 PM
expect fun getAddr(addr: CPointer<sockaddr>?)
- type
CPointer<sockaddr>?
isn’t allowed in common code Now I’ve created
expect fun getNameInfo(addrAsLong: Long, addrLength: UInt): String
and
Copy code
if (getIdAddr(addr.toLong(), addrLen) == LOCALHOST) {
    MHD_YES
} else {
    MHD_NO
}
but it looks like ugly
Oh… MacOS: socklen_t - UInt MinGW: socklen_t - Int 💩
8 Views