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

Opt-in purerlang implementation of gen_tcp and gen_udp using socket API #941

Merged
merged 1 commit into from
Dec 10, 2023

Conversation

fadushin
Copy link
Collaborator

@fadushin fadushin commented Nov 12, 2023

This PR adds the ability to use the gen_tcp and gen_udp interfaces using the OTP socket interface as a "back-end", eliminating the need for the native C drivers on generic_unix and ESP32.

Using the feature also allows use of the gen_tcp and gen_udp interfaces on the rp2040 platform.

This feature is still considered "experimental" and therefore is not currently documented. However, the configuration APIs follow the OTP inet_backend configuration option introduced in OTP-23.

This PR addresses issue #893

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 marked this pull request as ready for review November 14, 2023 02:47
@fadushin fadushin requested a review from pguyot November 17, 2023 15:41
libs/include/inet.hrl Outdated Show resolved Hide resolved
libs/include/inet.hrl Outdated Show resolved Hide resolved
@@ -29,6 +29,10 @@ extern "C" {

#define TAG "otp_socket"

#define AVM_LOGD(tag, format, ...) \
;
// fprintf(stderr, "D %s: " format " (%s:%i)\n", tag, ##__VA_ARGS__, __FILE__, __LINE__);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a leftover?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sort of. Since there is no way to configure log levels, I figured I'd leave these in place so they could be uncommented. But since they are offensive, I have removed them.

@@ -26,6 +26,10 @@

#define TAG "otp_socket"

#define AVM_LOGD(tag, format, ...) \
;
// fprintf(stderr, "D %s: " format " (%s:%i)\n", tag, ##__VA_ARGS__, __FILE__, __LINE__);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a leftover?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same

end,
% timer:sleep(50),

% erlang:display({closing, client, socket}),
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's remove debug code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed, as well as other locations in this module

@bettio
Copy link
Collaborator

bettio commented Dec 10, 2023

Just one question for my better understanding: did we place an additional gen_server in the middle between the caller and the port driver?

@fadushin
Copy link
Collaborator Author

fadushin commented Dec 10, 2023

Just one question for my better understanding: did we place an additional gen_server in the middle between the caller and the port driver?

No, just a module/function call, in the case of the inet driver.

In the case of the OTP socket driver, yes, there is a gen_server that manages the “state” of the gen_(tcp|udp)

Unfortunately, it’s not really clear in git, but the old gen_tcp.erl is essentially the same as the (new) gen_tcp_inet.erl, and similarly for the UDP module.

@bettio bettio merged commit 8d2990d into atomvm:master Dec 10, 2023
84 checks passed
@fadushin fadushin deleted the gen-sockets branch December 12, 2023 16:21
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