-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from inaka/ferigis.133.close_connection
[#133] create a method for closing the apns connection
- Loading branch information
Showing
6 changed files
with
29 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,13 @@ | |
%%% @copyright Inaka <[email protected]> | ||
%%% | ||
-module(apns). | ||
-author("Felipe Ripoll <felipes@inakanetworks.com>"). | ||
-author("Felipe Ripoll <felipe@inakanetworks.com>"). | ||
|
||
%% API | ||
-export([ start/0 | ||
, stop/0 | ||
, connect/1 | ||
, close_connection/1 | ||
]). | ||
|
||
%%%=================================================================== | ||
|
@@ -41,7 +42,7 @@ stop() -> | |
ok = application:stop(apns), | ||
ok. | ||
|
||
%% @doc Connect to APNs service with Provider Certificate | ||
%% @doc Connects to APNs service with Provider Certificate | ||
-spec connect( apns_connection:name() | ||
| apns_connection:connection()) -> {ok, pid()}. | ||
connect(ConnectionName) when is_atom(ConnectionName) -> | ||
|
@@ -51,6 +52,11 @@ connect(Connection) -> | |
{ok, _} = apns_sup:create_connection(Connection), | ||
{ok, whereis(apns_connection:name(Connection))}. | ||
|
||
%% @doc Closes the connection with APNs service. | ||
-spec close_connection(apns_connection:name()) -> ok. | ||
close_connection(ConnectionName) -> | ||
apns_connection:close_connection(ConnectionName). | ||
|
||
%%%=================================================================== | ||
%%% Internal Functions | ||
%%%=================================================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
%%% @copyright Inaka <[email protected]> | ||
%%% | ||
-module(apns_connection). | ||
-author("Felipe Ripoll <ferigis@inakanetworks.com>"). | ||
-author("Felipe Ripoll <felipe@inakanetworks.com>"). | ||
|
||
-behaviour(gen_server). | ||
|
||
|
@@ -30,6 +30,7 @@ | |
, certfile/1 | ||
, keyfile/1 | ||
, gun_connection/1 | ||
, close_connection/1 | ||
]). | ||
|
||
%% gen_server callbacks | ||
|
@@ -89,6 +90,11 @@ default_connection(ConnectionName) -> | |
, keyfile => Keyfile | ||
}. | ||
|
||
%% @doc Close the connection with APNs gracefully | ||
-spec close_connection(name()) -> ok. | ||
close_connection(ConnectionName) -> | ||
gen_server:cast(ConnectionName, stop). | ||
|
||
%% @doc Returns the gun's connection PID. This function is only used in tests. | ||
-spec gun_connection(name()) -> pid(). | ||
gun_connection(ConnectionName) -> | ||
|
@@ -118,6 +124,8 @@ handle_call(_Request, _From, State) -> | |
|
||
-spec handle_cast(Request :: term(), State) -> | ||
{noreply, State}. | ||
handle_cast(stop, State) -> | ||
{stop, normal, State}; | ||
handle_cast(_Request, State) -> | ||
{noreply, State}. | ||
|
||
|
@@ -134,8 +142,8 @@ handle_info(_Info, State) -> | |
{noreply, State}. | ||
|
||
-spec terminate( Reason :: (normal | shutdown | {shutdown, term()} | term()) | ||
, State :: map() | ||
) -> term(). | ||
, State :: state() | ||
) -> ok. | ||
terminate(_Reason, _State) -> | ||
ok. | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters