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