aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src/inet.erl
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2014-07-22 18:01:19 +0200
committerErlang/OTP <[email protected]>2014-07-22 18:01:19 +0200
commit52810718bcd607ebb538036bdbb87b5e94634984 (patch)
treeb6cc19578e968c38a2510585e481b98c279bf7c4 /lib/kernel/src/inet.erl
parent450f0f893b5d28e6d967b163111f8a8a6032b0e1 (diff)
parenta60f3d879dfcdd018f1fea20790be901fbafeae4 (diff)
downloadotp-52810718bcd607ebb538036bdbb87b5e94634984.tar.gz
otp-52810718bcd607ebb538036bdbb87b5e94634984.tar.bz2
otp-52810718bcd607ebb538036bdbb87b5e94634984.zip
Merge branch 'lukas/kernel/bind_with_fdopen/OTP-12061' into maint-r16
* lukas/kernel/bind_with_fdopen/OTP-12061: Fix default behaviour for legacy fdopen erts: Fix inet close on prebound fds kernel: When doing an fdopen we now also bind the fd to the specified addr/port
Diffstat (limited to 'lib/kernel/src/inet.erl')
-rw-r--r--lib/kernel/src/inet.erl33
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/kernel/src/inet.erl b/lib/kernel/src/inet.erl
index b1c9d56c2d..35236f4cb3 100644
--- a/lib/kernel/src/inet.erl
+++ b/lib/kernel/src/inet.erl
@@ -1246,9 +1246,9 @@ open(FdO, Addr, Port, Opts, Protocol, Family, Type, Module)
Error ->
Error
end;
-open(Fd, _Addr, _Port, Opts, Protocol, Family, Type, Module)
+open(Fd, Addr, Port, Opts, Protocol, Family, Type, Module)
when is_integer(Fd) ->
- fdopen(Fd, Opts, Protocol, Family, Type, Module).
+ fdopen(Fd, Addr, Port, Opts, Protocol, Family, Type, Module).
bindx(S, [Addr], Port0) ->
{IP, Port} = set_bindx_port(Addr, Port0),
@@ -1287,12 +1287,35 @@ change_bindx_0_port({_IP, _Port}=Addr, _AssignedPort) ->
{'ok', socket()} | {'error', posix()}.
fdopen(Fd, Opts, Protocol, Family, Type, Module) ->
- case prim_inet:fdopen(Protocol, Family, Type, Fd) of
+ fdopen(Fd, any, 0, Opts, Protocol, Family, Type, Module).
+
+fdopen(Fd, Addr, Port, Opts, Protocol, Family, Type, Module) ->
+ IsAnyAddr = (Addr == {0,0,0,0} orelse Addr == {0,0,0,0,0,0,0,0}
+ orelse Addr == any),
+ Bound = Port == 0 andalso IsAnyAddr,
+ case prim_inet:fdopen(Protocol, Family, Type, Fd, Bound) of
{ok, S} ->
case prim_inet:setopts(S, Opts) of
ok ->
- inet_db:register_socket(S, Module),
- {ok, S};
+ case if
+ Bound ->
+ %% We do not do any binding if default
+ %% port+addr options where given in order
+ %% to keep backwards compatability with
+ %% pre Erlang/TOP 17
+ {ok, ok};
+ is_list(Addr) ->
+ bindx(S, Addr, Port);
+ true ->
+ prim_inet:bind(S, Addr, Port)
+ end of
+ {ok, _} ->
+ inet_db:register_socket(S, Module),
+ {ok, S};
+ Error ->
+ prim_inet:close(S),
+ Error
+ end;
Error ->
prim_inet:close(S), Error
end;