aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaimo Niskanen <[email protected]>2011-09-28 12:08:49 +0200
committerRaimo Niskanen <[email protected]>2011-09-28 12:08:49 +0200
commitfde38fa8d3120e6aa479f7720654114df9cd4ec8 (patch)
tree082ef5d9fc6af70be3b593d160f06b8f90048ad7
parent32ad9d12c8d600495bb8c206967ffb3172786e3e (diff)
parent30937b22530827f0e4686494230d17a15ff7accb (diff)
downloadotp-fde38fa8d3120e6aa479f7720654114df9cd4ec8.tar.gz
otp-fde38fa8d3120e6aa479f7720654114df9cd4ec8.tar.bz2
otp-fde38fa8d3120e6aa479f7720654114df9cd4ec8.zip
Merge branch 'raimo/sctp-getsetopts-dev/OTP-9544' into dev
* raimo/sctp-getsetopts-dev/OTP-9544: erts,kernel: Bugfix - read SCTP socket options from right protocol layer erts: Fix bug SCTP send can only be called from controlling process
-rw-r--r--erts/emulator/drivers/common/inet_drv.c9
-rw-r--r--lib/kernel/test/gen_sctp_SUITE.erl57
2 files changed, 54 insertions, 12 deletions
diff --git a/erts/emulator/drivers/common/inet_drv.c b/erts/emulator/drivers/common/inet_drv.c
index 743c01d935..43114c6039 100644
--- a/erts/emulator/drivers/common/inet_drv.c
+++ b/erts/emulator/drivers/common/inet_drv.c
@@ -6539,7 +6539,7 @@ static int sctp_fill_opts(inet_descriptor* desc, char* buf, int buflen,
struct linger lg;
unsigned int sz = sizeof(lg);
- if (sock_getopt(desc->s, IPPROTO_SCTP, SO_LINGER,
+ if (sock_getopt(desc->s, SOL_SOCKET, SO_LINGER,
&lg, &sz) < 0) continue;
/* Fill in the response: */
PLACE_FOR(spec, i,
@@ -6575,7 +6575,7 @@ static int sctp_fill_opts(inet_descriptor* desc, char* buf, int buflen,
{
case INET_OPT_RCVBUF :
{
- proto = IPPROTO_SCTP;
+ proto = SOL_SOCKET;
type = SO_RCVBUF;
is_int = 1;
tag = am_recbuf;
@@ -6583,7 +6583,7 @@ static int sctp_fill_opts(inet_descriptor* desc, char* buf, int buflen,
}
case INET_OPT_SNDBUF :
{
- proto = IPPROTO_SCTP;
+ proto = SOL_SOCKET;
type = SO_SNDBUF;
is_int = 1;
tag = am_sndbuf;
@@ -7029,8 +7029,7 @@ static int sctp_fill_opts(inet_descriptor* desc, char* buf, int buflen,
i = LOAD_TUPLE(spec, i, 3);
/* Now, convert "spec" into the returnable term: */
- /* desc->caller = 0; What does it mean? */
- driver_output_term(desc->port, spec, i);
+ driver_send_term(desc->port, driver_caller(desc->port), spec, i);
FREE(spec);
(*dest)[0] = INET_REP_SCTP;
diff --git a/lib/kernel/test/gen_sctp_SUITE.erl b/lib/kernel/test/gen_sctp_SUITE.erl
index 03e734445c..1b534a5fc4 100644
--- a/lib/kernel/test/gen_sctp_SUITE.erl
+++ b/lib/kernel/test/gen_sctp_SUITE.erl
@@ -212,7 +212,9 @@ xfer_active(Config) when is_list(Config) ->
?line test_server:fail({unexpected,flush()})
end,
?line io:format("SbAssocId=~p~n", [SbAssocId]),
- ?line ok = gen_sctp:send(Sa, SaAssocId, 0, Data),
+ ?line ok =
+ do_from_other_process(
+ fun () -> gen_sctp:send(Sa, SaAssocId, 0, Data) end),
?line receive
{sctp,Sb,Loopback,Pa,
{[#sctp_sndrcvinfo{stream=Stream,
@@ -378,11 +380,14 @@ def_sndrcvinfo(Config) when is_list(Config) ->
end
end,
?line ok =
- gen_sctp:send(
- S2,
- #sctp_sndrcvinfo{stream=0, ppid=20, assoc_id=S2AssocId},
- <<"4: ",Data/binary>>),
- ?line case ok(gen_sctp:recv(S1)) of
+ do_from_other_process(
+ fun () ->
+ gen_sctp:send(
+ S2,
+ #sctp_sndrcvinfo{stream=0, ppid=20, assoc_id=S2AssocId},
+ <<"4: ",Data/binary>>)
+ end),
+ ?line case ok(do_from_other_process(fun() -> gen_sctp:recv(S1) end)) of
{Loopback,P2,
[#sctp_sndrcvinfo{
stream=0, ppid=20, context=0, assoc_id=S1AssocId}],
@@ -575,6 +580,8 @@ api_opts(doc) ->
api_opts(suite) ->
[];
api_opts(Config) when is_list(Config) ->
+ ?line Sndbuf = 32768,
+ ?line Recbuf = 65536,
?line {ok,S} = gen_sctp:open(0),
?line OSType = os:type(),
?line case {inet:setopts(S, [{linger,{true,2}}]),OSType} of
@@ -582,7 +589,15 @@ api_opts(Config) when is_list(Config) ->
ok;
{{error,einval},{unix,sunos}} ->
ok
- end.
+ end,
+ ?line ok = inet:setopts(S, [{sndbuf,Sndbuf}]),
+ ?line ok = inet:setopts(S, [{recbuf,Recbuf}]),
+ ?line case inet:getopts(S, [sndbuf]) of
+ {ok,[{sndbuf,SB}]} when SB >= Sndbuf -> ok
+ end,
+ ?line case inet:getopts(S, [recbuf]) of
+ {ok,[{recbuf,RB}]} when RB >= Recbuf -> ok
+ end.
implicit_inet6(Config) when is_list(Config) ->
?line Hostname = ok(inet:gethostname()),
@@ -638,3 +653,31 @@ implicit_inet6(S1, Addr) ->
{{0,0,0,0,0,0,0,0},P2} -> ok
end,
?line ok = gen_sctp:close(S2).
+
+
+
+do_from_other_process(Fun) ->
+ Parent = self(),
+ Ref = make_ref(),
+ Child =
+ spawn(fun () ->
+ try Fun() of
+ Result ->
+ Parent ! {Ref,Result}
+ catch
+ Class:Reason ->
+ Stacktrace = erlang:get_stacktrace(),
+ Parent ! {Ref,Class,Reason,Stacktrace}
+ end
+ end),
+ Mref = erlang:monitor(process, Child),
+ receive
+ {Ref,Result} ->
+ receive {'DOWN',Mref,_,_,_} -> Result end;
+ {Ref,Class,Reason,Stacktrace} ->
+ receive {'DOWN',Mref,_,_,_} ->
+ erlang:raise(Class, Reason, Stacktrace)
+ end;
+ {'DOWN',Mref,_,_,Reason} ->
+ erlang:exit(Reason)
+ end.