Skip to content

Commit

Permalink
fix(tunnel_client): add a fast termination method
Browse files Browse the repository at this point in the history
where we don't want to wait for the message queue to drain
  • Loading branch information
stakach committed Jul 18, 2024
1 parent 9ed2918 commit 5f29012
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: knx
version: 1.1.0
version: 1.1.1
crystal: ">= 0.36.1"

dependencies:
Expand Down
12 changes: 11 additions & 1 deletion src/knx/tunnel_client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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?
Expand Down

0 comments on commit 5f29012

Please sign in to comment.