summaryrefslogtreecommitdiff
path: root/components/dlink_bt/src/bt_connection.erl
diff options
context:
space:
mode:
Diffstat (limited to 'components/dlink_bt/src/bt_connection.erl')
-rw-r--r--components/dlink_bt/src/bt_connection.erl25
1 files changed, 19 insertions, 6 deletions
diff --git a/components/dlink_bt/src/bt_connection.erl b/components/dlink_bt/src/bt_connection.erl
index ab6d5da..a5fc3c5 100644
--- a/components/dlink_bt/src/bt_connection.erl
+++ b/components/dlink_bt/src/bt_connection.erl
@@ -41,6 +41,7 @@
remote_addr = "00:00:00:00:00:00",
channel = 0,
rfcomm_ref = undefined,
+ listen_ref = undefined,
mod = undefined,
func = undefined,
args = undefined
@@ -150,6 +151,7 @@ init({accept, Channel, ListenRef, Mod, Fun, Arg}) ->
{ok, #st{
channel = Channel,
rfcomm_ref = ARef,
+ listen_ref = ListenRef,
mod = Mod,
func = Fun,
args = Arg
@@ -221,7 +223,7 @@ handle_cast(connect, #st {
rfcomm_ref = ConnRef
}};
- { err, Error } ->
+ { error, Error } ->
?info("Failed to connect to ~p-~p", [ BTAddr, Channel]),
{ stop, { connect_failed, Error}, St }
end;
@@ -282,20 +284,31 @@ handle_info({rfcomm, _ConnRef, {data, Data}},
{noreply, State};
-handle_info({rfcomm_closed, ConnRef},
+handle_info({rfcomm, ConnRef, closed},
#st { remote_addr = BTAddr,
channel = Channel,
+ listen_ref = ListenRef,
mod = Mod,
func = Fun,
args = Arg } = State) ->
- ?debug("~p:handle_info(tcp_closed): BTAddr: ~p:~p ", [ ?MODULE, BTAddr, Channel]),
+ ?debug("~p:handle_info(bt_closed): BTAddr: ~p:~p ", [ ?MODULE, BTAddr, Channel]),
Mod:Fun(self(), BTAddr, Channel, closed, Arg),
bt_connection_manager:delete_connection_by_pid(self()),
- rfcomm_close:close(ConnRef),
+ rfcomm:close(ConnRef),
+
+ %% Fire up a new accept process to take care of the next incomign connectionX
+ gen_server:start_link(?MODULE, {accept,
+ Channel,
+ ListenRef,
+ Mod,
+ Fun,
+ Arg},[]),
+
+ %% Stop this process.
{stop, normal, State};
-handle_info({rfcomm_error, ConnRef},
+handle_info({rfcomm, ConnRef, error},
#st { remote_addr = BTAddr,
channel = Channel,
mod = Mod,
@@ -310,7 +323,7 @@ handle_info({rfcomm_error, ConnRef},
handle_info(_Info, State) ->
- ?warning("~p:handle_cast(): Unknown info: ~p", [ ?MODULE, _Info]),
+ ?warning("~p:handle_info(): Unknown info: ~p", [ ?MODULE, _Info]),
{noreply, State}.
%%--------------------------------------------------------------------