print_timer option
parent
188f4fc701
commit
af1c7e1875
|
@ -25,7 +25,9 @@ class Context
|
|||
class_property host = "0.0.0.0"
|
||||
class_property port_to_listen : UInt16 = 1234
|
||||
class_property timer_delay : Int32 = 30_000.to_i32
|
||||
|
||||
class_property print_messages = false
|
||||
class_property print_timer = false
|
||||
end
|
||||
|
||||
OptionParser.parse do |parser|
|
||||
|
@ -49,6 +51,10 @@ OptionParser.parse do |parser|
|
|||
Baguette::Context.verbosity = opt.to_i
|
||||
end
|
||||
|
||||
parser.on "-T", "--print-timer", "Print timer." do
|
||||
Context.print_timer = true
|
||||
end
|
||||
|
||||
parser.on "-M", "--print-messages", "Print messages received and sent." do
|
||||
Context.print_messages = true
|
||||
end
|
||||
|
@ -299,7 +305,7 @@ def websocket_switching_procedure (activefd : Int)
|
|||
rescue e
|
||||
Baguette::Log.error "Exception (receiving a message) #{e}"
|
||||
Context.context.remove_fd activefd
|
||||
return
|
||||
break
|
||||
end
|
||||
|
||||
# Checking the internals of WebSocket, then the contained IO within, to know if there is still something to read in the socket.
|
||||
|
@ -308,31 +314,39 @@ def websocket_switching_procedure (activefd : Int)
|
|||
if wsclient.closed?
|
||||
Baguette::Log.info "client #{activefd} is closing"
|
||||
Context.context.remove_fd activefd
|
||||
return
|
||||
break
|
||||
end
|
||||
|
||||
if message.nil?
|
||||
Baguette::Log.error "message received from #{activefd} is nil"
|
||||
Context.context.remove_fd activefd
|
||||
return
|
||||
if still_something_to_read
|
||||
Baguette::Log.info "Still something to read, but #{activefd} was removed"
|
||||
next
|
||||
end
|
||||
break
|
||||
end
|
||||
|
||||
case message
|
||||
when WebSocket::Error
|
||||
Baguette::Log.error "An error occured with client #{activefd}"
|
||||
Context.context.remove_fd activefd
|
||||
if still_something_to_read
|
||||
Baguette::Log.debug "Still something to read, but #{activefd} was removed"
|
||||
next
|
||||
end
|
||||
return
|
||||
when WebSocket::Ping
|
||||
Baguette::Log.debug "Received a ping message"
|
||||
if still_something_to_read
|
||||
Baguette::Log.info "Still something to read"
|
||||
Baguette::Log.debug "Still something to read"
|
||||
next
|
||||
end
|
||||
break
|
||||
when WebSocket::Pong
|
||||
Baguette::Log.debug "Received a pong message"
|
||||
if still_something_to_read
|
||||
Baguette::Log.info "Still something to read"
|
||||
Baguette::Log.debug "Still something to read"
|
||||
next
|
||||
end
|
||||
break
|
||||
|
@ -340,14 +354,15 @@ def websocket_switching_procedure (activefd : Int)
|
|||
Baguette::Log.debug "Received a close message"
|
||||
Context.context.remove_fd activefd
|
||||
if still_something_to_read
|
||||
Baguette::Log.info "Still something to read"
|
||||
Baguette::Log.debug "Still something to read"
|
||||
next
|
||||
end
|
||||
return
|
||||
break
|
||||
when WebSocket::NotFinal
|
||||
Baguette::Log.warning "Received only part of a message (not supported)"
|
||||
pp!
|
||||
if still_something_to_read
|
||||
Baguette::Log.info "Still something to read"
|
||||
Baguette::Log.debug "Still something to read"
|
||||
next
|
||||
end
|
||||
break
|
||||
|
@ -438,7 +453,7 @@ Context.service.loop do |event|
|
|||
begin
|
||||
case event
|
||||
when IPC::Event::Timer
|
||||
Baguette::Log.info "IPC::Event::Timer"
|
||||
Baguette::Log.info "IPC::Event::Timer" if Context.print_timer
|
||||
sending_ping_messages
|
||||
when IPC::Event::Connection
|
||||
Baguette::Log.debug "IPC::Event::Connection: #{event.fd}"
|
||||
|
|
Reference in New Issue