-
Notifications
You must be signed in to change notification settings - Fork 3k
Add Getaddrinfo interface for multiple DNS adresses #11653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@tymoteuszblochmobica, thank you for your changes. |
Why diversion from POSIX API? This is basically equivalent, return list of addresses to go through. I would prefer the POSIX, instead of making a new ways to achieve something that there has been standards for. |
Ok i can replace gethostbyname_multiple with int getaddrinfo(const char *restrict nodename, However need parameter for maximum adress count.
struct addrinfo { |
Is it possible to use So proposal would be:
Usage example could be:
Alternatively you could give hints like: It is not exactly POSIX, but something that you can easily relate to. Also does not need any extra types to be defined. Currently, I don't see any usecase for those fields in |
Its ok but im going to reuse nsapi_dns_query_multiple and this function needs maximum address count as one of arguments. |
According to POSIX, async version needs to be added either. struct gaicb { |
Origin definition We don use const char* service, but need interface name so it is replaced with interface_name to support multihoming DNS server select. Is it ok? |
Can we move the Most users don't specify the interface. |
Yes we can, but argument order will not be the same as original getaddrinfo |
0fbd134
to
e2b06ba
Compare
} | ||
} | ||
|
||
SocketAddress *temp = new (std::nothrow) SocketAddress [MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
temp
can now be NULL in case of out-of-memory, case, so should there be check for its validity? nsapi_dns_query_multiple
does not seem to check it either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Also update PR description |
@tymoteuszblochmobica still requires 4.2.0 release. The change was only internal. |
I mean testing purpose if whole CI pass successfuly after restart. |
@0xc0170 , just out of curiosity. If the CI has now turned green, it means that it checked out the latest master of |
New members are added to the network interface -getaddrinfo -getaddrinfo_async gethostbyname is unchanged but gethostbyname_async result param now contains results od DNS records found. Test cases for sync/async added added to DNS test folder.
e930845
to
8b2f4c2
Compare
CI can be restarted |
Test run: FAILEDSummary: 1 of 11 test jobs failed Failed test jobs:
|
The issue seems to be caused by some RAAS glitch:
|
CI restarted |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
all ready @tymoteuszblochmobica @michalpasztamobica (also client was released), correct? |
Yes, looks ready from our side. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AnttiKauppila I'm not a big fan of APIs forcing HEAP on our users. It's a bad habit for embedded systems and as we all know can lead to issues. We spend some time in Mbed Core to make sure that use of HEAP is optional. Is lwip/sockets or networking in general requires dynamic allocation in general? If not could we rethink how this API works? If you think it's ok with the dynamic memory and it doesn't stand out from the use pattern across connectivity, could we add a warning in doxygen that it will use dynamic memory/allocate memory on the heap.
@tymoteuszblochmobica @michalpasztamobica Can you answer this one? |
@0xc0170 , I think the final word belongs to @AnttiKauppila , so it's worth waiting for him to come back from holidays. The dns module has and always had a lot of dynamic allocations, so Tymoteusz adjusted his changes to the existing coding style. I think completely giving up dynamic allocation could become a waste of memory as we would have to allocate all buffers as static globals shared between functions, while now we can allocate only as much as is needed. I see some dynamically allocated variables which could potentially be moved to stack (for example here and here), if we really want to cut down on heap usage. Finally - if the usage of heap as we know it from the standard is considered dangerous or harmful in a particular use case, it is possible for the user to implement their own allocators that will be called on |
I don't think it is a realistic option to do a networked application without a heap. For example, DNS phase is done when you start your connections, makes lots of sense that all memory used by resolver is then freed, once we continue to connection phase, as there might be TLS/DTLS handshakes coming, which in turn require great amount of RAM as well. |
Description
Added getaddrinfo interface for multiple DNS adresses.
It uses existing nsapi_dns_query_multiple functions.
Sync and async version added to interface so it requires dependent libraries rebuild.
Pull request type
Reviewers
@mikaleppanen
@SeppoTakalo
@kjbracey-arm
@kivaisan
@AriParkkila
Release Notes
New members are added to the network interface
-getaddrinfo
-getaddrinfo_async
Both of them allocates space for results.
Function gethostbyname is unchanged but gethostbyname_async/getaddrinfo_async callback result param now contains number of DNS records found instead NSAPI_ERROR_OK =0 so definition of new callback for getaddrinfo_async is not needed.
Test cases for sync/async added added to DNS test folder.
SYNCHRONOUS_DNS_MULTI_IP
ASYNCHRONOUS_DNS_MULTI_IP