diff options
author | Sverker Eriksson <[email protected]> | 2017-08-24 20:34:16 +0200 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2017-11-15 20:10:33 +0100 |
commit | 966b0f9b4095984abd2c5196d40c4e15d5d1a06c (patch) | |
tree | 73b7fcee44b3340206f6fb62cf6ac13a45b1ed94 /lib/erl_interface | |
parent | d736e87ff94ab8191f33dca55516e6c1d440b915 (diff) | |
download | otp-966b0f9b4095984abd2c5196d40c4e15d5d1a06c.tar.gz otp-966b0f9b4095984abd2c5196d40c4e15d5d1a06c.tar.bz2 otp-966b0f9b4095984abd2c5196d40c4e15d5d1a06c.zip |
erl_interface: Refactor ei_accept_SUITE
in order to call ei_publish() separately.
Diffstat (limited to 'lib/erl_interface')
-rw-r--r-- | lib/erl_interface/test/ei_accept_SUITE.erl | 14 | ||||
-rw-r--r-- | lib/erl_interface/test/ei_accept_SUITE_data/ei_accept_test.c | 28 |
2 files changed, 37 insertions, 5 deletions
diff --git a/lib/erl_interface/test/ei_accept_SUITE.erl b/lib/erl_interface/test/ei_accept_SUITE.erl index e06ee762d7..8881eb85bd 100644 --- a/lib/erl_interface/test/ei_accept_SUITE.erl +++ b/lib/erl_interface/test/ei_accept_SUITE.erl @@ -59,7 +59,8 @@ ei_accept(Config) when is_list(Config) -> spawn(F), Port = 6543, - {ok, Fd, _Node} = ei_accept(P, Port), + {ok, ListenFd} = ei_publish(P, Port), + {ok, Fd, _Node} = ei_accept(P, ListenFd), TermReceived= ei_receive(P, Fd), io:format("Sent ~p received ~p ~n", [TermToSend, TermReceived]), TermToSend= TermReceived, @@ -137,8 +138,15 @@ ei_connect_init(P, Num, Cookie, Creation) -> {term,Int} when is_integer(Int) -> Int end. -ei_accept(P, PortNo) -> - send_command(P, ei_accept, [PortNo]), +ei_publish(P, PortNo) -> + send_command(P, ei_publish, [PortNo]), + case get_term(P) of + {term,{ListenFd, EpmdFd, _}} when ListenFd >= 0, EpmdFd >= 0 -> {ok, ListenFd}; + {term,{_, _, Errno}} -> {error,Errno} + end. + +ei_accept(P, ListenFd) -> + send_command(P, ei_accept, [ListenFd]), case get_term(P) of {term,{Fd, _, Node}} when Fd >= 0 -> {ok, Fd, Node}; {term,{_Fd, Errno, _Node}} -> {error,Errno} diff --git a/lib/erl_interface/test/ei_accept_SUITE_data/ei_accept_test.c b/lib/erl_interface/test/ei_accept_SUITE_data/ei_accept_test.c index 7b81ee5491..2355192cc2 100644 --- a/lib/erl_interface/test/ei_accept_SUITE_data/ei_accept_test.c +++ b/lib/erl_interface/test/ei_accept_SUITE_data/ei_accept_test.c @@ -43,6 +43,7 @@ #include "ei_runner.h" static void cmd_ei_connect_init(char* buf, int len); +static void cmd_ei_publish(char* buf, int len); static void cmd_ei_accept(char* buf, int len); static void cmd_ei_receive(char* buf, int len); static void cmd_ei_unpublish(char* buf, int len); @@ -58,6 +59,7 @@ static struct { void (*func)(char* buf, int len); } commands[] = { "ei_connect_init", 3, cmd_ei_connect_init, + "ei_publish", 1, cmd_ei_publish, "ei_accept", 1, cmd_ei_accept, "ei_receive", 1, cmd_ei_receive, "ei_unpublish", 0, cmd_ei_unpublish @@ -149,11 +151,10 @@ static int my_listen(int port) return listen_fd; } -static void cmd_ei_accept(char* buf, int len) +static void cmd_ei_publish(char* buf, int len) { int index = 0; int listen, r; - ErlConnect conn; long port; ei_x_buff x; int i; @@ -170,6 +171,29 @@ static void cmd_ei_accept(char* buf, int len) #ifdef VXWORKS save_fd(i); #endif + /* send listen-fd, result and errno */ + ei_x_new_with_version(&x); + ei_x_encode_tuple_header(&x, 3); + ei_x_encode_long(&x, listen); + ei_x_encode_long(&x, i); + ei_x_encode_long(&x, erl_errno); + send_bin_term(&x); + ei_x_free(&x); +} + +static void cmd_ei_accept(char* buf, int len) +{ + int index = 0; + int r; + ErlConnect conn; + long listen; + ei_x_buff x; + int i; + + /* get port */ + if (ei_decode_long(buf, &index, &listen) < 0) + fail("expected int (listen fd)"); + r = ei_accept(&ec, listen, &conn); #ifdef VXWORKS save_fd(r); |