|
36 | 36 | -include("tls_connection.hrl"). |
37 | 37 |
|
38 | 38 | %% Initial Erlang process setup |
39 | | --export([tls_start_link/7, |
40 | | - dtls_start_link/7, |
| 39 | +-export([tls_start_link/2, |
| 40 | + dtls_start_link/2, |
41 | 41 | init/1]). |
42 | 42 |
|
43 | 43 | %% TLS connection setup |
|
110 | 110 | %%% Initial Erlang process setup |
111 | 111 | %%-------------------------------------------------------------------- |
112 | 112 | %%-------------------------------------------------------------------- |
113 | | --spec tls_start_link(client | server, ssl:host(), inet:port_number(), port(), tuple(), pid(), tuple()) -> |
| 113 | +-spec tls_start_link(pid(), list()) -> |
114 | 114 | {ok, pid()} | ignore | {error, ssl:reason()}. |
115 | 115 | %% |
116 | 116 | %% Description: Creates a process which calls Module:init/1 to |
117 | | -%% choose appropriat gen_statem and initialize. |
| 117 | +%% choose appropriate gen_statem and initialize. |
118 | 118 | %%-------------------------------------------------------------------- |
119 | | -tls_start_link(Role, Host, Port, Socket, {SslOpts, _, _} = Options, User, CbInfo) -> |
120 | | - ReceiverOpts = maps:get(receiver_spawn_opts, SslOpts, []), |
121 | | - Opts = [link | proplists:delete(link, ReceiverOpts)], |
122 | | - Pid = proc_lib:spawn_opt(?MODULE, init, [[Role, self(), Host, Port, Socket, Options, User, CbInfo]], Opts), |
| 119 | +tls_start_link(ConnSupv, ReceiverSpawnOpts) -> |
| 120 | + Opts = [link | proplists:delete(link, ReceiverSpawnOpts)], |
| 121 | + Pid = proc_lib:spawn_opt(?MODULE, init, [ConnSupv], Opts), |
123 | 122 | {ok, Pid}. |
124 | 123 |
|
125 | 124 | %%-------------------------------------------------------------------- |
126 | | --spec dtls_start_link(client | server, ssl:host(), inet:port_number(), port(), tuple(), pid(), tuple()) -> |
| 125 | +-spec dtls_start_link(pid(), list()) -> |
127 | 126 | {ok, pid()} | ignore | {error, ssl:reason()}. |
128 | 127 | %% |
129 | 128 | %% Description: Creates a gen_statem process which calls Module:init/1 to |
130 | 129 | %% initialize. |
131 | 130 | %%-------------------------------------------------------------------- |
132 | | -dtls_start_link(Role, Host, Port, Socket, {SslOpts, _, _} = Options, User, CbInfo) -> |
133 | | - ReceiverOpts = maps:get(receiver_spawn_opts, SslOpts, []), |
134 | | - Opts = [link | proplists:delete(link, ReceiverOpts)], |
135 | | - Pid = proc_lib:spawn_opt(?MODULE, init, [[Role, Host, Port, Socket, Options, User, CbInfo]], Opts), |
| 131 | +dtls_start_link(ConnSupv, ReceiverSpawnOpts) -> |
| 132 | + Opts = [link | proplists:delete(link, ReceiverSpawnOpts)], |
| 133 | + Pid = proc_lib:spawn_opt(?MODULE, init, [ConnSupv], Opts), |
136 | 134 | {ok, Pid}. |
137 | 135 |
|
138 | 136 |
|
139 | 137 | %%-------------------------------------------------------------------- |
140 | | --spec init(list()) -> no_return(). |
| 138 | +-spec init(pid()) -> no_return(). |
141 | 139 | %% Description: Initialization |
| 140 | +%% We are linked through the supervisors here so either we die or get |
| 141 | +%% the message from the supervisor. |
142 | 142 | %%-------------------------------------------------------------------- |
143 | | -init([Role, Sup, Host, Port, Socket, {TLSOpts, EmOpts, Trackers}, User, CbInfo]) -> |
| 143 | +init(ConnSupv) -> |
| 144 | + receive |
| 145 | + {ConnSupv, options, Args} -> |
| 146 | + init_statem(Args) |
| 147 | + end. |
| 148 | + |
| 149 | +init_statem([Role, Sup, Host, Port, Socket, {TLSOpts, EmOpts, Trackers}, User, CbInfo]) -> |
144 | 150 | process_flag(trap_exit, true), |
145 | 151 |
|
146 | 152 | {ok, {_, Sender,_,_}} = supervisor:which_child(Sup, sender), |
@@ -176,7 +182,7 @@ init([Role, Sup, Host, Port, Socket, {TLSOpts, EmOpts, Trackers}, User, CbInfo]) |
176 | 182 | tls_server_connection:init([Role, Sender, Tab|InitArgs]) |
177 | 183 | end |
178 | 184 | end; |
179 | | -init([Role, Host, Port, Socket, {DTLSOpts,EmOpts,Trackers}, User, CbInfo]) -> |
| 185 | +init_statem([Role, Host, Port, Socket, {DTLSOpts,EmOpts,Trackers}, User, CbInfo]) -> |
180 | 186 | process_flag(trap_exit, true), |
181 | 187 |
|
182 | 188 | init_label(Role, Host, Port, DTLSOpts), |
|
0 commit comments