dev
Karchnu 4 years ago
parent f6c0498e46
commit 6fcfd592ba

@ -115,7 +115,7 @@ class WebSocket < HTTP::WebSocket
getter? closed = false
def finalize
puts "WebSocket garbage collection!!"
# puts "WebSocket garbage collection!!"
# super
end
end
@ -123,7 +123,7 @@ end
class WrappedTCPFileDescriptor < TCPSocket
# do not close the connection when garbage collected!!
def finalize
puts "WrappedTCPFileDescriptor garbage collection!!"
# puts "WrappedTCPFileDescriptor garbage collection!!"
# super
end
end

@ -161,7 +161,7 @@ def handle_new_clients(service, server)
# only the client callbacks are changed, since the associated server is a simple libipc service
LibIPC.ipc_switching_callbacks service.pointer, client.fd, proc_cb_in, proc_cb_out
puts "#{CBLUE}new client:#{CRESET} #{client.fd}" unless CLI.verbosity == 0
info "#{CBLUE}new client:#{CRESET} #{client.fd}"
rescue e
puts "Exception in handle_new_client: #{CRED}#{e}#{CRESET}"
unless client.nil?
@ -170,7 +170,7 @@ rescue e
end
def ws_cb_out(fd : Int32, pm : Pointer(LibIPC::Message))
puts "OUT fd is #{fd}"
info "OUT fd is #{fd}"
wsclient = Context.context.fd_to_websocket[fd]
message = IPC::Message.new pm
@ -192,33 +192,28 @@ rescue e
end
def ws_cb_in(fd : Int32, pm : LibIPC::Message*)
puts "IN fd is #{fd}"
info "IN fd is #{fd}"
wsclient = Context.context.fd_to_websocket[fd]
puts
puts
puts "before run_once"
message = nil
begin
message = wsclient.run_once
puts "after the run_once"
rescue e
puts "#{CRED}run_once FAILED#{CRESET}: #{e}"
# Context.context.remove_fd fd
Context.context.remove_fd fd
return LibIPC::IPCCB::Error
end
if wsclient.closed?
puts "#{CBLUE}client is closed#{CRESET}"
# Context.context.remove_fd fd
info "#{CBLUE}client is closed#{CRESET}"
Context.context.remove_fd fd
return LibIPC::IPCCB::Closing
end
if message.nil?
puts "#{CRED}message is nil#{CRESET}"
# Context.context.remove_fd fd
Context.context.remove_fd fd
return LibIPC::IPCCB::Closing
end
@ -234,28 +229,28 @@ def ws_cb_in(fd : Int32, pm : LibIPC::Message*)
case message
when WebSocket::Error
puts "#{CRED}An error occured#{CRESET}"
# Context.context.remove_fd fd
Context.context.remove_fd fd
return LibIPC::IPCCB::Error
when WebSocket::Ping
puts "#{CBLUE}Received a ping message#{CRESET}"
# Context.context.remove_fd fd
Context.context.remove_fd fd
return LibIPC::IPCCB::Ignore
when WebSocket::Pong
puts "#{CBLUE}Received a pong message#{CRESET}"
return LibIPC::IPCCB::Ignore
when WebSocket::Close
puts "#{CBLUE}Received a close message#{CRESET}"
# Context.context.remove_fd fd
Context.context.remove_fd fd
return LibIPC::IPCCB::Closing
when WebSocket::NotFinal
puts "#{CBLUE}Received only part of a message: NOT IMPLEMENTED#{CRESET}"
# Context.context.remove_fd fd
Context.context.remove_fd fd
return LibIPC::IPCCB::Error
when Bytes
# TODO: when receiving a binary message
# we should test the format and maybe its content
puts "#{CBLUE}Received a binary message: NOT IMPLEMENTED, YET#{CRESET}"
# Context.context.remove_fd fd
Context.context.remove_fd fd
return LibIPC::IPCCB::Error
else
puts "#{CRED}Received a websocket message with unknown type#{CRESET}"
@ -293,8 +288,8 @@ def main
service.timer = CLI.timer_delay
service.loop do |event|
info "current state of the context:"
service.pp
# info "current state of the context:"
# service.pp
case event
when IPC::Event::Timer
info "#{CORANGE}IPC::Event::Timer#{CRESET}"

Loading…
Cancel
Save