summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRickard Green <rickard@erlang.org>2020-10-21 22:37:54 +0200
committerRickard Green <rickard@erlang.org>2020-10-22 17:50:02 +0200
commit76a647835f0e858f896f57702a56d3596eb14d1a (patch)
treea344d21b030a6cf2478c733030ee7bf3265f419f
parent3f21ce1e6a5d6c548867fa4bc9a8c666c626ade1 (diff)
downloaderlang-76a647835f0e858f896f57702a56d3596eb14d1a.tar.gz
Look up IOV_MAX instead of assuming 16
-rw-r--r--erts/emulator/drivers/common/inet_drv.c33
-rw-r--r--erts/emulator/test/distribution_SUITE.erl50
2 files changed, 78 insertions, 5 deletions
diff --git a/erts/emulator/drivers/common/inet_drv.c b/erts/emulator/drivers/common/inet_drv.c
index 567f22199b..00708f1478 100644
--- a/erts/emulator/drivers/common/inet_drv.c
+++ b/erts/emulator/drivers/common/inet_drv.c
@@ -1155,9 +1155,24 @@ typedef struct {
#define TCP_MAX_PACKET_SIZE 0x4000000 /* 64 M */
-#define MAX_VSIZE 16 /* Max number of entries allowed in an I/O
- * vector sock_sendv().
- */
+/* Max number of entries allowed in an I/O vector sock_sendv(). */
+#if defined(__WIN32__)
+/*
+ * Windows 95, 98, and ME is limited to 16, but we do not
+ * support those. Documentation unfortunately does not say
+ * anything about newer windows, so we guess 1024 which
+ * seems to be what most systems use...
+ */
+#define MAX_VSIZE 1024
+#elif !defined(NO_SYSCONF)
+static int iov_max;
+#define MAX_VSIZE iov_max
+#elif defined(IOV_MAX)
+#define MAX_VSIZE IOV_MAX
+#else
+/* POSIX require at least 16 */
+#define MAX_VSIZE 16
+#endif
static int tcp_inet_init(void);
static void tcp_inet_stop(ErlDrvData);
@@ -4127,6 +4142,18 @@ static int inet_init()
if (!sock_init())
goto error;
+#if !defined(__WIN32__) && !defined(NO_SYSCONF)
+ iov_max = (int) sysconf(_SC_IOV_MAX);
+ if (iov_max < 0) {
+#ifdef IOV_MAX
+ iov_max = IOV_MAX;
+#else
+ iov_max = 16; /* min value required by POSIX */
+#endif
+ }
+ ASSERT(iov_max >= 16);
+#endif
+
if (0 != erl_drv_tsd_key_create("inet_buffer_stack_key", &buffer_stack_key))
goto error;
diff --git a/erts/emulator/test/distribution_SUITE.erl b/erts/emulator/test/distribution_SUITE.erl
index 8ec5ceb3ff..d945023f61 100644
--- a/erts/emulator/test/distribution_SUITE.erl
+++ b/erts/emulator/test/distribution_SUITE.erl
@@ -75,7 +75,8 @@
system_limit/1,
hopefull_data_encoding/1,
hopefull_export_fun_bug/1,
- mk_hopefull_data/0]).
+ mk_hopefull_data/0,
+ huge_iovec/1]).
%% Internal exports.
-export([sender/3, receiver2/2, dummy_waiter/0, dead_process/0,
@@ -105,7 +106,8 @@ all() ->
{group, message_latency},
{group, bad_dist}, {group, bad_dist_ext},
start_epmd_false, epmd_module, system_limit,
- hopefull_data_encoding, hopefull_export_fun_bug].
+ hopefull_data_encoding, hopefull_export_fun_bug,
+ huge_iovec].
groups() ->
[{bulk_send, [], [bulk_send_small, bulk_send_big, bulk_send_bigbig]},
@@ -2720,6 +2722,50 @@ hopefull_export_fun_bug(Config) when is_list(Config) ->
2, fun blipp:blapp/7],
{dummy, dummy@dummy} ! Msg. % Would crash on debug VM
+huge_iovec(Config) ->
+ %% Make sure that we can pass a term that will produce
+ %% an io-vector larger than IOV_MAX over the distribution...
+ %% IOV_MAX is typically 1024. Currently we produce an
+ %% element in the io-vector for all off heap binaries...
+ NoBinaries = 1 bsl 14,
+ BinarySize = 65,
+ {ok, Node} = start_node(huge_iovec),
+ P = spawn_link(Node,
+ fun () ->
+ receive {From, Data} ->
+ From ! {self(), Data}
+ end
+ end),
+ RBL = mk_rand_bin_list(BinarySize, NoBinaries),
+ %% Check that it actually will produce a huge iovec...
+ %% If we set a limit on the size of the binaries
+ %% that will produce an element in the io-vector
+ %% we need to adjust this testcase...
+ true = length(term_to_iovec(RBL)) >= NoBinaries,
+ P ! {self(), RBL},
+ receive
+ {P, EchoedRBL} ->
+ stop_node(Node),
+ RBL = EchoedRBL
+ end,
+ ok.
+
+mk_rand_bin_list(Bytes, Binaries) ->
+ mk_rand_bin_list(Bytes, Binaries, []).
+
+mk_rand_bin_list(_Bytes, 0, Acc) ->
+ Acc;
+mk_rand_bin_list(Bytes, Binaries, Acc) ->
+ mk_rand_bin_list(Bytes, Binaries-1, [mk_rand_bin(Bytes) | Acc]).
+
+mk_rand_bin(Bytes) ->
+ mk_rand_bin(Bytes, []).
+
+mk_rand_bin(0, Data) ->
+ list_to_binary(Data);
+mk_rand_bin(N, Data) ->
+ mk_rand_bin(N-1, [rand:uniform(256) - 1 | Data]).
+
%%% Utilities