Skip to content

Commit

Permalink
fix logs in client and dot expect connack in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
kickster97 committed Sep 24, 2024
1 parent 7cf822c commit f2e453a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion spec/mqtt/integrations/connect_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module MqttSpecs
it "should replace the already connected client [MQTT-3.1.4-2]" do
with_server do |server|
with_client_io(server) do |io|
connect(io, false)
connect(io)
with_client_io(server) do |io2|
connect(io2)
io.should be_closed
Expand Down
2 changes: 1 addition & 1 deletion src/lavinmq/mqtt/broker.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module LavinMQ
def session_present?(client_id : String, clean_session) : Bool
session = @sessions[client_id]?
pp "session_present? #{session.inspect}"
return false if session.nil? || clean_session && session.set_clean_session
return false if session.nil? || ( clean_session && session.set_clean_session )
true
end

Expand Down
18 changes: 9 additions & 9 deletions src/lavinmq/mqtt/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module LavinMQ

private def read_loop
loop do
Log.trace { "waiting for packet" }
@log.trace { "waiting for packet" }
packet = read_and_handle_packet
# The disconnect packet has been handled and the socket has been closed.
# If we dont breakt the loop here we'll get a IO/Error on next read.
Expand All @@ -52,9 +52,9 @@ module LavinMQ
rescue ex : ::MQTT::Protocol::Error::PacketDecode
@socket.close
rescue ex : MQTT::Error::Connect
Log.warn { "Connect error #{ex.inspect}" }
rescue ex : ::IO::EOFError
Log.info { "eof #{ex.inspect}" }
@log.warn { "Connect error #{ex.inspect}" }
rescue ex : ::IO::Error
@log.warn(exception: ex) { "Read Loop error" }
ensure
pp "ensuring"
publish_will if @will
Expand All @@ -65,7 +65,7 @@ module LavinMQ

def read_and_handle_packet
packet : MQTT::Packet = MQTT::Packet.from_io(@io)
Log.info { "recv #{packet.inspect}" }
@log.info { "recv #{packet.inspect}" }
@recv_oct_count += packet.bytesize

case packet
Expand Down Expand Up @@ -147,14 +147,14 @@ module LavinMQ

def start_session(client) : MQTT::Session
if @clean_session
Log.trace { "clear session" }
@log.trace { "clear session" }
@broker.clear_session(client)
end
@broker.start_session(client)
end

def disconnect_session(client)
Log.trace { "disconnect session" }
@log.trace { "disconnect session" }
@broker.clear_session(client)
end

Expand All @@ -163,14 +163,14 @@ module LavinMQ
if will = @will
end
rescue ex
Log.warn { "Failed to publish will: #{ex.message}" }
@log.warn { "Failed to publish will: #{ex.message}" }
end

def update_rates
end

def close(reason = "")
Log.trace { "Client#close" }
@log.trace { "Client#close" }
@closed = true
@socket.close
end
Expand Down

0 comments on commit f2e453a

Please sign in to comment.