Skip to content

Commit

Permalink
Add esockd_connection:gc/1, esockd_transport:gc1 functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Feng Lee committed Mar 13, 2017
1 parent 9e8802d commit 061863b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions examples/ssl/src/ssl_echo_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
%%%
%%% @end
%%%-----------------------------------------------------------------------------

-module(ssl_echo_server).

% start
Expand Down Expand Up @@ -62,6 +63,7 @@ loop(Conn) ->
{ok, PeerName} = Conn:peername(),
io:format("~s - ~p~n", [esockd_net:format(peername, PeerName), Data]),
Conn:send(Data),
Conn:gc(), %% Try GC?
loop(Conn);
{error, Reason} ->
io:format("tcp ~s~n", [Reason]),
Expand Down
6 changes: 6 additions & 0 deletions src/esockd_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
-export([send/2, async_send/2, recv/2, recv/3, async_recv/2, async_recv/3,
shutdown/2, close/1, fast_close/1]).

-export([gc/1]).

-type(parameter() :: any()).

-type(connection() :: {?MODULE, list(parameter())}).
Expand Down Expand Up @@ -216,3 +218,7 @@ close(?CONN_MOD(Sock)) ->
fast_close(?CONN_MOD(Sock)) ->
?Transport:fast_close(Sock).

%% @doc GC the SSL Connection.
gc(?CONN_MOD(Sock)) ->
?Transport:gc(Sock).

18 changes: 13 additions & 5 deletions src/esockd_transport.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@

-export([type/1]).

-export([listen/2, send/2, port_command/2,
recv/2, recv/3,
async_recv/2, async_recv/3,
controlling_process/2,
close/1, fast_close/1]).
-export([listen/2, send/2, port_command/2, recv/2, recv/3, async_recv/2, async_recv/3,
controlling_process/2, close/1, fast_close/1]).

-export([getopts/2, setopts/2, getstat/2]).

-export([sockname/1, peername/1, peercert/1, shutdown/2]).

-export([gc/1]).

%% tcp -> sslsocket
-export([ssl_upgrade_fun/1]).

Expand Down Expand Up @@ -261,3 +260,12 @@ ssl_upgrade_fun(SslOpts) ->
end
end.

gc(Sock) when is_port(Sock) ->
ok;
%% Defined in ssl/src/ssl_api.hrl:
%% -record(sslsocket, {fd = nil, pid = nil}).
gc(#ssl_socket{ssl = {sslsocket, _, Pid}}) when is_pid(Pid) ->
erlang:garbage_collect(Pid);
gc(_Sock) ->
ok.

0 comments on commit 061863b

Please sign in to comment.