Skip to content
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

Add support for net:getaddrinfo/1,2 #903

Merged
merged 1 commit into from
Nov 3, 2023
Merged

Conversation

fadushin
Copy link
Collaborator

This PR adds support for the net:getaddrinfo/1,2 family of functions.

Addresses Issue #902

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

@fadushin fadushin force-pushed the net-addrinfo2 branch 5 times, most recently from 8b15181 to 4ff90ec Compare October 29, 2023 00:09
@fadushin fadushin changed the title Added support for net:getaddrinfo/1,2 Add support for net:getaddrinfo/1,2 Oct 29, 2023
@fadushin fadushin marked this pull request as ready for review October 29, 2023 16:34
@fadushin fadushin requested review from pguyot and bettio October 29, 2023 16:34
src/libAtomVM/otp_net.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_net.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_net.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_net.c Outdated Show resolved Hide resolved
@fadushin fadushin force-pushed the net-addrinfo2 branch 3 times, most recently from aa1f891 to 0136c71 Compare October 31, 2023 00:52
@fadushin fadushin requested a review from pguyot October 31, 2023 02:59
@fadushin
Copy link
Collaborator Author

Open question -- is this slightly over-engineered? Here's why. This functionality is being implemented as an entirely new component, with (in the case of ESP32) a Config entry, a NIF registration macro, etc. Is this really necessary?

An alternative approach would be to draw a link-time dependency between this code and the OTP-socket code, which would pull this code into the runtime "for free". The linkage might be a little "artificial", but I would be okay with that. I guess it is a question of whether anyone would have use for this feature without the OTP socket code, and I think the answer to that is, "probably not".

Thoughts?

Also, it just occurred to me that this code might not be linking into the Pico port, so that should be investigated (and might be solved by the above proposal)

src/libAtomVM/interop.c Outdated Show resolved Hide resolved
src/platforms/generic_unix/lib/sys.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_net.c Show resolved Hide resolved
src/libAtomVM/term.h Outdated Show resolved Hide resolved
@@ -87,6 +87,7 @@ extern "C" {
#define TUPLE_SIZE(elems) ((int) (elems + 1))
#define CONS_SIZE 2
#define REFC_BINARY_CONS_OFFSET 4
#define LIST_SIZE(num_elements, element_size) (num_elements * (element_size + CONS_SIZE))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further nitpicking (this might save us a lot of headache).
Macro should be rewritten as: ((num_elements) * ((element_size) + CONS_SIZE)).
If you do something like: LIST_SIZE(a_elements + b_elements, TUPLE_SIZE(3)) it will expand as: (a_elements + b_elements * (TUPLE_SIZE(3) + CONS_SIZE)).
I can assure that debugging this is very painful.

Copy link
Collaborator Author

@fadushin fadushin Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's nitpicking at all, and I should have picked up on this first, so my bad. Nice catch. Please re-review change.

src/libAtomVM/interop.h Outdated Show resolved Hide resolved
@fadushin fadushin marked this pull request as draft November 3, 2023 11:01
@fadushin fadushin marked this pull request as ready for review November 3, 2023 11:01
@bettio bettio merged commit 6643ea7 into atomvm:master Nov 3, 2023
83 of 84 checks passed
@fadushin fadushin deleted the net-addrinfo2 branch November 9, 2023 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants