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 preliminary support for the OTP socket interface #757

Merged
merged 1 commit into from
Oct 22, 2023

Conversation

fadushin
Copy link
Collaborator

@fadushin fadushin commented Aug 13, 2023

This PR adds preliminary support for the OTP socket interface, which exposes APIs for low-level socket operations, as defined in OTP 22 and later. This implementation aims to be API-compatible with the OTP implementation, though many parts of the interface have yet to be implemented.

Key features of this implementation include the following:

  • A new socket driver has been added, which uses the BSD socket interface to implement the OTP socket driver
  • This driver is supported on generic UNIX and ESP32 platforms. Where possible, a common codebase is used, to minimize the cost of maintenance.

The following operations are supported:

  • socket:open/3
  • socket:close/1
  • socket:bind/2
  • socket:listen/1,2
  • socket:accept/1
  • socket:sockname/1
  • socket:peername/1
  • socket:recv/1
  • socket:recvfrom/1
  • socket:send/2
  • socket:sendto/3
  • socket:setopt/3
  • socket:connect/2
  • socket:shutdown/2

Currently, the TCP and UDP protocols is supported. Additional work is needed to support other data types and protocols, as well as name resolution via the OTP net:addrinfo interface.

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 draft August 13, 2023 21:34
doc/src/programmers-guide.md Outdated Show resolved Hide resolved
doc/src/programmers-guide.md Outdated Show resolved Hide resolved
doc/src/programmers-guide.md Outdated Show resolved Hide resolved
doc/src/programmers-guide.md Outdated Show resolved Hide resolved
doc/src/programmers-guide.md Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
tests/libs/estdlib/test_tcp_socket.erl Outdated Show resolved Hide resolved
tests/libs/estdlib/tests.erl Show resolved Hide resolved
@fadushin fadushin force-pushed the otp-socket-resource branch 4 times, most recently from 704db5f to db1f7f2 Compare August 19, 2023 20:06
Copy link
Collaborator

@pguyot pguyot left a comment

Choose a reason for hiding this comment

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

I'd say it's ok to not do non-blocking sockets for a first version of this good work, but we need socket:shutdown/2 as socket:close/1 semantics are misleading.

doc/src/programmers-guide.md Outdated Show resolved Hide resolved
doc/src/programmers-guide.md Outdated Show resolved Hide resolved
doc/src/programmers-guide.md Outdated Show resolved Hide resolved
doc/src/programmers-guide.md Outdated Show resolved Hide resolved
libs/estdlib/src/socket.erl Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Show resolved Hide resolved
tests/libs/estdlib/test_tcp_socket.erl Outdated Show resolved Hide resolved
tests/libs/estdlib/test_udp_socket.erl Outdated Show resolved Hide resolved
tests/libs/estdlib/test_udp_socket.erl Outdated Show resolved Hide resolved
@fadushin fadushin force-pushed the otp-socket-resource branch 2 times, most recently from 75a4d79 to 0e807ca Compare September 11, 2023 00:29
src/libAtomVM/otp_socket.c Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
@fadushin fadushin force-pushed the otp-socket-resource branch 3 times, most recently from 059ee51 to 3fdf221 Compare September 23, 2023 13:45
@fadushin fadushin force-pushed the otp-socket-resource branch 5 times, most recently from ddae90d to 13514ab Compare September 24, 2023 21:53
@fadushin fadushin marked this pull request as ready for review September 24, 2023 22:52
@fadushin fadushin force-pushed the otp-socket-resource branch 2 times, most recently from 67a938b to a45aa10 Compare September 30, 2023 16:19
@fadushin fadushin force-pushed the otp-socket-resource branch 2 times, most recently from a525145 to 3b219be Compare October 13, 2023 13:24
libs/estdlib/src/socket.erl Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
src/platforms/esp32/components/avm_sys/sys.c Outdated Show resolved Hide resolved
src/platforms/generic_unix/lib/sys.c Show resolved Hide resolved
src/platforms/generic_unix/lib/otp_socket_platform.h Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
src/libAtomVM/otp_socket.c Outdated Show resolved Hide resolved
This PR adds preliminary support for the OTP socket interface, which exposes APIs for low-level socket operations, as defined in OTP 22 and later. This implementation aims to be API-compatible with the OTP implementation, though many parts of the interface have yet to be implemented.

Key features of this implementation include the following:

* A new socket driver has been added, which uses the BSD socket interface to implement the OTP socket driver
* This driver is supported on generic UNIX and ESP32 platforms. Where possible, a common codebase is used, to minimize the cost of maintenance.

The following operations are supported:

* socket:open/3
* socket:close/1
* socket:bind/2
* socket:listen/1,2
* socket:accept/1
* socket:sockname/1
* socket:peername/1
* socket:recv/1
* socket:recvfrom/1
* socket:send/2
* socket:sendto/3
* socket:setopt/3
* socket:connect/2
* socket:shutdown/2

Currently, the TCP and UDP protocols is supported. Additional work is needed to support other data types and protocols, as well as name resolution via the OTP net:addrinfo interface.

Signed-off-by: Fred Dushin <fred@dushin.net>
Copy link
Collaborator

@UncleGrumpy UncleGrumpy left a comment

Choose a reason for hiding this comment

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

I spotted a couple typos, and a missing edoc parm.

Edit:
Disregard. I forgot to publish my comments earlier, they are outdated, and seem to be fixed.

@bettio bettio merged commit 68ba03a into atomvm:master Oct 22, 2023
83 checks passed
@fadushin fadushin deleted the otp-socket-resource branch October 23, 2023 02:14
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.

4 participants