Skip to content

Commit

Permalink
Add otpbp_gen_sctp with connect/3, connect_init/3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ledest committed Oct 26, 2023
1 parent 2921864 commit 17659c9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ Funs = [{application, get_supervisor, 1},
{gen_event, start_monitor, 0},
{gen_event, start_monitor, 1},
{gen_event, start_monitor, 2},
{gen_sctp, connect, 3},
{gen_sctp, connect_init, 3},
{gen_server, start_monitor, 3},
{gen_server, start_monitor, 4},
{gen_statem, enter_loop, 4},
Expand All @@ -205,6 +207,7 @@ Funs = [{application, get_supervisor, 1},
{httpd_util, integer_to_hexlist, 1},
{httpd_util, strip, 1},
{httpd_util, suffix, 1},
{inet, ensure_sockaddr, 1},
{inet, info, 1},
{inet, ipv4_mapped_ipv6_address, 1},
{io_lib, format, 3},
Expand Down Expand Up @@ -272,6 +275,7 @@ Funs = [{application, get_supervisor, 1},
{pg2, start, 0}, % OTP < 24.0
{pg2, start_link, 0}, % OTP < 24.0
{pg2, which_groups, 0}, % OTP < 24.0
{prim_socket, enc_sockaddr, 1},
{proc_lib, init_fail, 2},
{proc_lib, init_fail, 3},
{proc_lib, start_monitor, 3},
Expand Down
31 changes: 31 additions & 0 deletions src/otpbp_gen_sctp.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-module(otpbp_gen_sctp).

-compile({parse_transform, otpbp_pt}).

-ifndef(HAVE_gen_sctp__connect_3).
% OTP 24.3
-export([connect/3]).
-endif.
-ifndef(HAVE_gen_sctp__connect_init_3).
% OTP 24.3
-export([connect_init/3]).
-endif.

-ifndef(HAVE_gen_sctp__connect_3).
connect(S, SockAddr, Opts) when is_port(S), is_map(SockAddr), is_list(Opts) ->
case inet_db:lookup_socket(S) of
{ok, Mod} -> Mod:connect(S, inet:ensure_sockaddr(SockAddr), Opts, false);
Error -> Error
end;
connect(S, SockAddr, Opts) -> error(badarg, [S, SockAddr, Opts, infinity]).
-endif.

-ifndef(HAVE_gen_sctp__connect_init_3).
connect_init(S, SockAddr, Opts) when is_port(S), is_map(SockAddr), is_list(Opts) ->
case inet_db:lookup_socket(S) of
{ok, Mod} -> Mod:connect(S, inet:ensure_sockaddr(SockAddr), Opts, nowait);
Error -> Error
end;
connect_init(S, SockAddr, Opts) -> error(badarg, [S, SockAddr, Opts, infinity]).
-endif.

1 change: 1 addition & 0 deletions src/otpbp_pt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
{{gen, debug_options, 2}, otpbp_gen},
{{gen_event, [start, start_link], 2}, otpbp_gen_event},
{{gen_event, start_monitor, [0, 1, 2]}, otpbp_gen_event},
{{geb_sctp, [connect, connect_init], 3}, otpbp_gen_sctp},
{{gen_server, start_monitor, [3, 4]}, otpbp_gen_server},
{{gen_statem, enter_loop, 4}, otpbp_gen_statem},
{{inet, [ensure_sockaddr, info, ipv4_mapped_ipv6_address], 1}, otpbp_inet},
Expand Down

0 comments on commit 17659c9

Please sign in to comment.