diff --git a/shard.yml b/shard.yml index cbfbda9..f5fbdf6 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: knx -version: 1.1.0 +version: 1.1.1 crystal: ">= 0.36.1" dependencies: diff --git a/src/knx/tunnel_client.cr b/src/knx/tunnel_client.cr index dd9678a..dfafa04 100644 --- a/src/knx/tunnel_client.cr +++ b/src/knx/tunnel_client.cr @@ -88,6 +88,7 @@ class KNX # establish comms def connect : Nil return if connected? + raise "client has been shutdown" if @channel.closed? send KNX::ConnectRequest.new(@control) end @@ -97,12 +98,21 @@ class KNX send KNX::ConnectStateRequest.new(@channel_id, @control) end - # close comms + # perform a graceful disconnect def disconnect : Nil return unless connected? send KNX::DisconnectRequest.new(@channel_id, @control) end + # perform a hard and fast disconnect, instance is not re-usable + def shutdown! : Nil + return unless connected? + @mutex.synchronize { @request_queue.clear } + @channel.close + @connected = false + @on_transmit.try &.call(KNX::DisconnectRequest.new(@channel_id, @control).to_slice) rescue nil + end + # perform an action / query def request(message : KNX::CEMI) raise "not connected" unless connected?