/erts/preloaded/src/prim_inet.erl
67 open(Protocol, Family, Type) ->
68 open(Protocol, Family, Type, [], ?INET_REQ_OPEN, []).
69
70 open(Protocol, Family, Type, Opts) ->
71 open(Protocol, Family, Type, Opts, ?INET_REQ_OPEN, []).
72
73 %% FDOPEN(tcp|udp|sctp, inet|inet6|local, stream|dgram|seqpacket, integer())
74
75 fdopen(Protocol, Family, Type, Fd) when is_integer(Fd) ->
76 fdopen(Protocol, Family, Type, Fd, true).
77
78 fdopen(Protocol, Family, Type, Fd, Bound)
79 when is_integer(Fd), is_boolean(Bound) ->
80 open(Protocol, Family, Type, [], ?INET_REQ_FDOPEN,
81 [?int32(Fd), enc_value_2(bool, Bound)]).
82
83 open(Protocol, Family, Type, Opts, Req, Data) ->
84 Drv = protocol2drv(Protocol),
85 AF = enc_family(Family),
86 T = enc_type(Type),
87 try erlang:open_port({spawn_driver,Drv}, [binary]) of
88 S ->
89 case setopts(S, Opts) of
90 ok ->
91 case ctl_cmd(S, Req, [AF,T,Data]) of
92 {ok,_} -> {ok,S};
93 {error,_}=E1 ->
94 close(S),
95 E1
96 end;
97 {error,_}=E2 ->
98 close(S),
99 E2
100 end
101 catch
102 %% The only (?) way to get here is to try to open
103 %% the sctp driver when it does not exist (badarg)
104 error:badarg -> {error, eprotonosupport};
105 %% system_limit if out of port slots
106 error:system_limit -> {error, system_limit}
107 end.
root/workplace/otp/lib/kernel/src/inet.erl
1338 open(FdO, Addr, Port, Opts, Protocol, Family, Type, Module)
1339 when is_integer(FdO), FdO < 0;
1340 is_list(FdO) ->
1341 OpenOpts =
1342 if is_list(FdO) -> FdO;
1343 true -> []
1344 end,
1345 case prim_inet:open(Protocol, Family, Type, OpenOpts) of
1346 {ok,S} ->
1347 case prim_inet:setopts(S, Opts) of
1348 ok when Addr =:= undefined ->
1349 inet_db:register_socket(S, Module),
1350 {ok,S};
1351 ok ->
1352 case bind(S, Addr, Port) of
1353 {ok, _} ->
1354 inet_db:register_socket(S, Module),
1355 {ok,S};
1356 Error ->
1357 prim_inet:close(S),
1358 Error
1359 end;
1360 Error ->
1361 prim_inet:close(S),
1362 Error
1363 end;
1364 Error ->
1365 Error
1366 end;
1367 open(Fd, Addr, Port, Opts, Protocol, Family, Type, Module)
1368 when is_integer(Fd) ->
1369 fdopen(Fd, Addr, Port, Opts, Protocol, Family, Type, Module).
root/workplace/otp/lib/kernel/src/inet_sctp.erl
52 case inet:sctp_options(Opts, ?MODULE) of
53 {ok,#sctp_opts{fd=Fd,ifaddr=Addr,port=Port,type=Type,opts=SOs}} ->
54 inet:open(Fd, Addr, Port, SOs, ?PROTO, ?FAMILY, Type, ?MODULE);
55 Error -> Error
56 end.
/root/workplace/otp/lib/kernel/src/inet.erl
1002 sctp_module(Opts) ->
1003 mod(
1004 Opts, sctp_module, undefined,
1005 #{inet => inet_sctp, inet6 => inet6_sctp}).
/root/workplace/otp/lib/kernel/src/inet_db.erl
771 %%
772 %% Register socket Modules
773 %%
774 register_socket(Socket, Module) when is_port(Socket), is_atom(Module) ->
775 try erlang:port_set_data(Socket, Module)
776 catch
777 error:badarg -> false
778 end.
779
780 unregister_socket(Socket) when is_port(Socket) ->
781 ok. %% not needed any more
783 lookup_socket(Socket) when is_port(Socket) ->
784 try erlang:port_get_data(Socket) of
785 Module when is_atom(Module) -> {ok,Module};
786 _ -> {error,closed}
787 catch
788 error:badarg -> {error,closed}
789 end.
/root/workplace/otp/lib/kernel/src/gen_sctp.erl
open(Opts0) when is_list(Opts0) ->
128 {Mod, Opts} = inet:sctp_module(Opts0),
129 case Mod:open(Opts) of
130 {error,badarg} ->
131 erlang:error(badarg, [Opts]);
132 {error,einval} ->
133 erlang:error(badarg, [Opts]);
134 Result -> Result
135 end;
136 open(Port) when is_integer(Port) ->
137 open([{port,Port}]);
138 open(X) ->
139 erlang:error(badarg, [X]).
do_connect(S, Addr, Port, Opts, Timeout, ConnWait) when is_port(S), is_list(Opts) ->
262 case inet_db:lookup_socket(S) of263 {ok,Mod} ->
264 case Mod:getserv(Port) of
265 {ok,Port} ->
266 try inet:start_timer(Timeout) of
267 Timer ->
268 try Mod:getaddr(Addr, Timer) of
269 {ok,IP} ->
270 ConnectTimer = if ConnWait == false ->
271 nowait;
272 true ->
273 Timer
274 end,
275 Mod:connect(S, IP, Port, Opts, ConnectTimer);
276 Error -> Error
277 after
278 _ = inet:stop_timer(Timer)
279 end
280 catch
281 error:badarg ->
282 badarg
283 end;
284 Error -> Error
285 end;
286 Error -> Error
287 end;
288 do_connect(_S, _Addr, _Port, _Opts, _Timeout, _ConnWait) ->
289 badarg.