From 9e34d5b91fda4c1021090fa00a8921cc2c8d2cb8 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 7 Mar 2019 17:27:44 +0100 Subject: [socket] Preliminary - make socket configurable Preliminary work to make socket configurable (enable and disable). OTP-15658 --- erts/configure.in | 22 ++++++++++++++++++++++ erts/emulator/Makefile.in | 11 +++++++++-- erts/preloaded/src/erl_init.erl | 20 +++++++++++++++++--- 3 files changed, 48 insertions(+), 5 deletions(-) (limited to 'erts') diff --git a/erts/configure.in b/erts/configure.in index 5f969a0a8b..f17572142d 100644 --- a/erts/configure.in +++ b/erts/configure.in @@ -1329,6 +1329,28 @@ LIBS=$zlib_save_LIBS fi AC_SUBST(Z_LIB) + +dnl ------------- +dnl esock +dnl ------------- + +AC_ARG_ENABLE(esock, +AS_HELP_STRING([--enable-esock], [enable builtin experimental socket (as a nif) support (default)]) +AS_HELP_STRING([--disable-esock], [disable builtin experimental socket (as a nif) support])) + +dnl Default value +USE_ESOCK=yes + +if test "x$enable_esock" = "xyes"; then + USE_ESOCK=yes +else + if test "x$enable_esock" = "xno"; then + USE_ESOCK=no + fi +fi +AC_SUBST(USE_ESOCK) + + dnl dnl This test kindly borrowed from Tcl dnl diff --git a/erts/emulator/Makefile.in b/erts/emulator/Makefile.in index 448f41b523..1c85c4e827 100644 --- a/erts/emulator/Makefile.in +++ b/erts/emulator/Makefile.in @@ -843,6 +843,14 @@ ESOCK_RUN_OBJS = \ $(OBJDIR)/socket_dbg.o \ $(OBJDIR)/socket_tarray.o \ $(OBJDIR)/socket_util.o +ifeq ($(USE_ESOCK), yes) +ESOCK_NIF_OBJS = \ + $(OBJDIR)/socket_nif.o \ + $(OBJDIR)/net_nif.o +else +ESOCK_NIF_OBJS = \ + $(OBJDIR)/net_nif.o +endif else ESOCK_RUN_OBJS = endif @@ -903,8 +911,7 @@ NIF_OBJS = \ $(OBJDIR)/prim_buffer_nif.o \ $(OBJDIR)/prim_file_nif.o \ $(OBJDIR)/zlib_nif.o \ - $(OBJDIR)/socket_nif.o \ - $(OBJDIR)/net_nif.o + $(ESOCK_NIF_OBJS) ifeq ($(TARGET),win32) DRV_OBJS = \ diff --git a/erts/preloaded/src/erl_init.erl b/erts/preloaded/src/erl_init.erl index 6edead362c..a650367c25 100644 --- a/erts/preloaded/src/erl_init.erl +++ b/erts/preloaded/src/erl_init.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2000-2016. All Rights Reserved. +%% Copyright Ericsson AB 2000-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -35,8 +35,8 @@ start(Mod, BootArgs) -> erl_tracer:on_load(), prim_buffer:on_load(), prim_file:on_load(), - socket:on_load(), - net:on_load(), + conditional_load(socket), % socket:on_load(), + net:on_load(), % This needs to be loaded since it contains 'other' funcs... %% Proceed to the specified boot module run(Mod, boot, BootArgs). @@ -48,3 +48,17 @@ run(M, F, A) -> true -> M:F(A) end. + +conditional_load(Mod) -> + conditional_load(Mod, erlang:loaded()). + +conditional_load(_Mod, []) -> + ok; +conditional_load(Mod, [Mod|_]) -> + Mod:on_load(); +conditional_load(Mod, [_|T]) -> + conditional_load(Mod, T). + + + + -- cgit v1.2.3 From 953f39ad8ce262d1104bd7e29338e43153bbd123 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 7 Mar 2019 18:14:40 +0100 Subject: [socket] Preloaded (erts) app file The optional socket module is now not included in the app file if esock is not enabled. OTP-15658 --- erts/preloaded/src/Makefile | 21 +++++++++++++++++---- erts/preloaded/src/erts.app.src | 3 +-- 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'erts') diff --git a/erts/preloaded/src/Makefile b/erts/preloaded/src/Makefile index efeb92dce9..27d450c873 100644 --- a/erts/preloaded/src/Makefile +++ b/erts/preloaded/src/Makefile @@ -1,7 +1,7 @@ # # %CopyrightBegin% # -# Copyright Ericsson AB 2008-2018. All Rights Reserved. +# Copyright Ericsson AB 2008-2019. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,14 +33,22 @@ STATIC_EBIN=../ebin include $(ERL_TOP)/erts/vsn.mk include $(ERL_TOP)/lib/kernel/vsn.mk +ifeq ($(USE_ESOCK), yes) +PRE_LOADED_ERL_ESOCK_MODULES = \ + socket \ + net +else +PRE_LOADED_ERL_ESOCK_MODULES = \ + net +endif + PRE_LOADED_ERL_MODULES = \ erl_prim_loader \ init \ prim_buffer \ prim_file \ prim_inet \ - socket \ - net \ + $(PRE_LOADED_ERL_ESOCK_MODULES) \ zlib \ prim_zip \ erl_init \ @@ -73,6 +81,11 @@ STATIC_TARGET_FILES = $(PRE_LOADED_MODULES:%=$(STATIC_EBIN)/%.$(EMULATOR)) APP_FILE= erts.app APP_SRC= $(APP_FILE).src APP_TARGET= $(STATIC_EBIN)/$(APP_FILE) +ifeq ($(USE_ESOCK), yes) +APP_ESOCK_MODS= net, socket +else +APP_ESOCK_MODS= net +endif KERNEL_SRC=$(ERL_TOP)/lib/kernel/src @@ -94,7 +107,7 @@ copy: cp *.beam $(STATIC_EBIN) $(APP_TARGET): $(APP_SRC) $(ERL_TOP)/erts/vsn.mk - $(vsn_verbose)sed -e 's;%VSN%;$(VSN);' $< > $@ + $(vsn_verbose)sed -e 's;%VSN%;$(VSN);' -e 's;%ESOCK_MODS%;$(APP_ESOCK_MODS);' $< > $@ include $(ERL_TOP)/make/otp_release_targets.mk diff --git a/erts/preloaded/src/erts.app.src b/erts/preloaded/src/erts.app.src index c2a8511b6d..132397b478 100644 --- a/erts/preloaded/src/erts.app.src +++ b/erts/preloaded/src/erts.app.src @@ -36,8 +36,7 @@ atomics, counters, zlib, - net, - socket + %ESOCK_MODS% ]}, {registered, []}, {applications, []}, -- cgit v1.2.3 From b6c6aba478e314f60647bf2868eb4ebc59d3c719 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 19 Mar 2019 18:19:49 +0100 Subject: [socket|net] Final prep The config options --[en|dis]able-esock now works as expected. --- erts/configure.in | 2 +- erts/emulator/Makefile.in | 35 +++++++++++++++++++++++++++-------- erts/preloaded/ebin/erl_init.beam | Bin 1820 -> 1280 bytes erts/preloaded/ebin/net.beam | Bin 5940 -> 2460 bytes erts/preloaded/src/erl_init.erl | 24 +++++++++++++++--------- erts/preloaded/src/net.erl | 3 ++- 6 files changed, 45 insertions(+), 19 deletions(-) (limited to 'erts') diff --git a/erts/configure.in b/erts/configure.in index f17572142d..2538505ee7 100644 --- a/erts/configure.in +++ b/erts/configure.in @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. -*-m4-*- dnl %CopyrightBegin% dnl -dnl Copyright Ericsson AB 1997-2018. All Rights Reserved. +dnl Copyright Ericsson AB 1997-2019. All Rights Reserved. dnl dnl Licensed under the Apache License, Version 2.0 (the "License"); dnl you may not use this file except in compliance with the License. diff --git a/erts/emulator/Makefile.in b/erts/emulator/Makefile.in index 1c85c4e827..a9f3bb8e89 100644 --- a/erts/emulator/Makefile.in +++ b/erts/emulator/Makefile.in @@ -633,6 +633,15 @@ GENERATE += $(TTF_DIR)/driver_tab.c # This list must be consistent with PRE_LOADED_MODULES in # erts/preloaded/src/Makefile. +ifeq ($(USE_ESOCK), yes) +ESOCK_PRELOAD_BEAM = \ + $(ERL_TOP)/erts/preloaded/ebin/socket.beam \ + $(ERL_TOP)/erts/preloaded/ebin/net.beam +else +ESOCK_PRELOAD_BEAM = \ + $(ERL_TOP)/erts/preloaded/ebin/net.beam +endif + PRELOAD_BEAM = $(ERL_TOP)/erts/preloaded/ebin/erts_code_purger.beam \ $(ERL_TOP)/erts/preloaded/ebin/erl_init.beam \ $(ERL_TOP)/erts/preloaded/ebin/init.beam \ @@ -641,8 +650,7 @@ PRELOAD_BEAM = $(ERL_TOP)/erts/preloaded/ebin/erts_code_purger.beam \ $(ERL_TOP)/erts/preloaded/ebin/prim_inet.beam \ $(ERL_TOP)/erts/preloaded/ebin/prim_file.beam \ $(ERL_TOP)/erts/preloaded/ebin/zlib.beam \ - $(ERL_TOP)/erts/preloaded/ebin/socket.beam \ - $(ERL_TOP)/erts/preloaded/ebin/net.beam \ + $(ESOCK_PRELOAD_BEAM) \ $(ERL_TOP)/erts/preloaded/ebin/prim_zip.beam \ $(ERL_TOP)/erts/preloaded/ebin/erl_prim_loader.beam \ $(ERL_TOP)/erts/preloaded/ebin/erlang.beam \ @@ -835,6 +843,15 @@ EMU_OBJS = \ $(OBJDIR)/beam_catches.o $(OBJDIR)/code_ix.o \ $(OBJDIR)/beam_ranges.o + +ifeq ($(USE_ESOCK), yes) + +# WE ARE USING ESOCK + +ESOCK_NIF_OBJS = \ + $(OBJDIR)/socket_nif.o \ + $(OBJDIR)/net_nif.o + ifneq ($(TARGET), win32) # These are *currently* only needed for non-win32, # since the nif-functions for socket and net are basically @@ -843,18 +860,20 @@ ESOCK_RUN_OBJS = \ $(OBJDIR)/socket_dbg.o \ $(OBJDIR)/socket_tarray.o \ $(OBJDIR)/socket_util.o -ifeq ($(USE_ESOCK), yes) -ESOCK_NIF_OBJS = \ - $(OBJDIR)/socket_nif.o \ - $(OBJDIR)/net_nif.o else -ESOCK_NIF_OBJS = \ - $(OBJDIR)/net_nif.o +ESOCK_RUN_OBJS = endif + else + +# WE ARE *NOT* USING ESOCK + +ESOCK_NIF_OBJS = ESOCK_RUN_OBJS = + endif + RUN_OBJS += \ $(OBJDIR)/erl_alloc.o $(OBJDIR)/erl_mtrace.o \ $(OBJDIR)/erl_alloc_util.o $(OBJDIR)/erl_goodfit_alloc.o \ diff --git a/erts/preloaded/ebin/erl_init.beam b/erts/preloaded/ebin/erl_init.beam index 81be5b021a..fed41173e2 100644 Binary files a/erts/preloaded/ebin/erl_init.beam and b/erts/preloaded/ebin/erl_init.beam differ diff --git a/erts/preloaded/ebin/net.beam b/erts/preloaded/ebin/net.beam index ebb1296b95..6b823ea0a4 100644 Binary files a/erts/preloaded/ebin/net.beam and b/erts/preloaded/ebin/net.beam differ diff --git a/erts/preloaded/src/erl_init.erl b/erts/preloaded/src/erl_init.erl index a650367c25..d209c4033b 100644 --- a/erts/preloaded/src/erl_init.erl +++ b/erts/preloaded/src/erl_init.erl @@ -35,8 +35,7 @@ start(Mod, BootArgs) -> erl_tracer:on_load(), prim_buffer:on_load(), prim_file:on_load(), - conditional_load(socket), % socket:on_load(), - net:on_load(), % This needs to be loaded since it contains 'other' funcs... + conditional_load(socket, [socket, net]), % socket:on_load(), net:on_load(), %% Proceed to the specified boot module run(Mod, boot, BootArgs). @@ -49,15 +48,22 @@ run(M, F, A) -> M:F(A) end. -conditional_load(Mod) -> - conditional_load(Mod, erlang:loaded()). +conditional_load(CondMod, Mods2Load) -> + conditional_load(CondMod, erlang:loaded(), Mods2Load). -conditional_load(_Mod, []) -> +conditional_load(_CondMod, [], _Mods2LOad) -> ok; -conditional_load(Mod, [Mod|_]) -> - Mod:on_load(); -conditional_load(Mod, [_|T]) -> - conditional_load(Mod, T). +conditional_load(CondMod, [CondMod|_], Mods2Load) -> + on_load(Mods2Load); +conditional_load(CondMod, [_|T], Mods2Load) -> + conditional_load(CondMod, T, Mods2Load). + +on_load([]) -> + ok; +on_load([Mod|Mods]) -> + Mod:on_load(), + on_load(Mods). + diff --git a/erts/preloaded/src/net.erl b/erts/preloaded/src/net.erl index a24b5c8ce3..0b069aa5c7 100644 --- a/erts/preloaded/src/net.erl +++ b/erts/preloaded/src/net.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2018-2018. All Rights Reserved. +%% Copyright Ericsson AB 2018-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -334,3 +334,4 @@ nif_if_index2name(_Id) -> nif_if_names() -> erlang:nif_error(undef). + -- cgit v1.2.3 From d332837ce419996729cdfebcf646943de91efa95 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 28 Mar 2019 12:55:35 +0100 Subject: [socket|net] Preloaded now built with latest compiler OTP-15658 --- erts/preloaded/ebin/erl_init.beam | Bin 1280 -> 1280 bytes erts/preloaded/ebin/net.beam | Bin 2460 -> 2460 bytes 2 files changed, 0 insertions(+), 0 deletions(-) (limited to 'erts') diff --git a/erts/preloaded/ebin/erl_init.beam b/erts/preloaded/ebin/erl_init.beam index fed41173e2..9ede2fcbc6 100644 Binary files a/erts/preloaded/ebin/erl_init.beam and b/erts/preloaded/ebin/erl_init.beam differ diff --git a/erts/preloaded/ebin/net.beam b/erts/preloaded/ebin/net.beam index 6b823ea0a4..2d9c25fbb0 100644 Binary files a/erts/preloaded/ebin/net.beam and b/erts/preloaded/ebin/net.beam differ -- cgit v1.2.3 From 83ba567c07f061649ddb3b850f91319c2d053fd7 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 28 Mar 2019 14:41:43 +0100 Subject: [socket|net] Fixed beams Forgot about using 'otp_build update_preloaded --no-commit' when updating the preloaded and compiled with plain erlc... Caused problems for dyalizer... OTP-15658 --- erts/preloaded/ebin/erl_init.beam | Bin 1280 -> 2312 bytes erts/preloaded/ebin/net.beam | Bin 2460 -> 5960 bytes 2 files changed, 0 insertions(+), 0 deletions(-) (limited to 'erts') diff --git a/erts/preloaded/ebin/erl_init.beam b/erts/preloaded/ebin/erl_init.beam index 9ede2fcbc6..0313988e3e 100644 Binary files a/erts/preloaded/ebin/erl_init.beam and b/erts/preloaded/ebin/erl_init.beam differ diff --git a/erts/preloaded/ebin/net.beam b/erts/preloaded/ebin/net.beam index 2d9c25fbb0..8b5ee52cfa 100644 Binary files a/erts/preloaded/ebin/net.beam and b/erts/preloaded/ebin/net.beam differ -- cgit v1.2.3 From e87bc034ae3f13cfcfab8677a10a088850c747a0 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 28 Mar 2019 14:44:45 +0100 Subject: [socket|net|test] Update test suites to handle disabled esock --- erts/emulator/test/net_SUITE.erl | 17 +++++++++++------ erts/emulator/test/socket_SUITE.erl | 31 ++++++++++++++++++------------- 2 files changed, 29 insertions(+), 19 deletions(-) (limited to 'erts') diff --git a/erts/emulator/test/net_SUITE.erl b/erts/emulator/test/net_SUITE.erl index 1a973cacb2..6111fc76a5 100644 --- a/erts/emulator/test/net_SUITE.erl +++ b/erts/emulator/test/net_SUITE.erl @@ -127,12 +127,17 @@ api_basic_cases() -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% init_per_suite(Config) -> - case os:type() of - {win32, _} -> - not_yet_implemented(); - _ -> - %% ?LOGGER:start(), - Config + case lists:member(socket, erlang:loaded()) of + true -> + case os:type() of + {win32, _} -> + not_yet_implemented(); + _ -> + %% ?LOGGER:start(), + Config + end; + false -> + {skip, "esock disabled"} end. end_per_suite(_) -> diff --git a/erts/emulator/test/socket_SUITE.erl b/erts/emulator/test/socket_SUITE.erl index cefbe4c1f8..e3545ccbf9 100644 --- a/erts/emulator/test/socket_SUITE.erl +++ b/erts/emulator/test/socket_SUITE.erl @@ -1385,22 +1385,27 @@ ttest_ssockt_csockt_cases() -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% init_per_suite(Config) -> - case os:type() of - {win32, _} -> - not_yet_implemented(); - _ -> - case quiet_mode(Config) of - default -> - ?LOGGER:start(), - Config; - Quiet -> - ?LOGGER:start(Quiet), - [{esock_test_quiet, Quiet}|Config] - end + case lists:member(socket, erlang:loaded()) of + true -> + case os:type() of + {win32, _} -> + (catch not_yet_implemented()); + _ -> + case quiet_mode(Config) of + default -> + ?LOGGER:start(), + Config; + Quiet -> + ?LOGGER:start(Quiet), + [{esock_test_quiet, Quiet}|Config] + end + end; + false -> + {skip, "esock disabled"} end. end_per_suite(_) -> - ?LOGGER:stop(), + (catch ?LOGGER:stop()), ok. -- cgit v1.2.3 From b49f68d5d8a256a7a0847d939b2da8a4be6c728a Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 2 Apr 2019 15:36:18 +0200 Subject: [net] Improvements (ahum) when --disable-esock The net module uses socket, but when the system has been built with --disable-esock, there is no socket... --- erts/preloaded/ebin/net.beam | Bin 5960 -> 6140 bytes erts/preloaded/src/net.erl | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'erts') diff --git a/erts/preloaded/ebin/net.beam b/erts/preloaded/ebin/net.beam index 8b5ee52cfa..f61b2b4a69 100644 Binary files a/erts/preloaded/ebin/net.beam and b/erts/preloaded/ebin/net.beam differ diff --git a/erts/preloaded/src/net.erl b/erts/preloaded/src/net.erl index 0b069aa5c7..13d2e3a117 100644 --- a/erts/preloaded/src/net.erl +++ b/erts/preloaded/src/net.erl @@ -178,12 +178,28 @@ getnameinfo(SockAddr, [] = _Flags) -> getnameinfo(#{family := Fam, addr := _Addr} = SockAddr, Flags) when ((Fam =:= inet) orelse (Fam =:= inet6)) andalso (is_list(Flags) orelse (Flags =:= undefined)) -> - nif_getnameinfo(socket:ensure_sockaddr(SockAddr), Flags); + nif_getnameinfo((catch ensure_sockaddr(SockAddr)), Flags); getnameinfo(#{family := Fam, path := _Path} = SockAddr, Flags) when (Fam =:= local) andalso (is_list(Flags) orelse (Flags =:= undefined)) -> nif_getnameinfo(SockAddr, Flags). +%% This function is intended to "handle" the case when the user +%% has built their (OTP) system with "--disable-esock". +%% That means the socket module does not exist. This is not really +%% a problem since the nif_getnameinfo won't work either (since +%% the nif file is not part of the system). The result of calling +%% getnameinfo will be a undef exception (erlang:nif_error(undef)). +%% +%% The only functions in this module that actually work in this case +%% (--disable-esock) is the depricated stuff (call, cast, ...). +%% +ensure_sockaddr(SockAddr) -> + try socket:ensure_sockaddr(SockAddr) + catch + error:undef:_ -> + undefined + end. %% =========================================================================== %% -- cgit v1.2.3