Messages--
parent
f6c0498e46
commit
6fcfd592ba
|
@ -115,7 +115,7 @@ class WebSocket < HTTP::WebSocket
|
||||||
getter? closed = false
|
getter? closed = false
|
||||||
|
|
||||||
def finalize
|
def finalize
|
||||||
puts "WebSocket garbage collection!!"
|
# puts "WebSocket garbage collection!!"
|
||||||
# super
|
# super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -123,7 +123,7 @@ end
|
||||||
class WrappedTCPFileDescriptor < TCPSocket
|
class WrappedTCPFileDescriptor < TCPSocket
|
||||||
# do not close the connection when garbage collected!!
|
# do not close the connection when garbage collected!!
|
||||||
def finalize
|
def finalize
|
||||||
puts "WrappedTCPFileDescriptor garbage collection!!"
|
# puts "WrappedTCPFileDescriptor garbage collection!!"
|
||||||
# super
|
# super
|
||||||
end
|
end
|
||||||
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
|
# 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
|
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
|
rescue e
|
||||||
puts "Exception in handle_new_client: #{CRED}#{e}#{CRESET}"
|
puts "Exception in handle_new_client: #{CRED}#{e}#{CRESET}"
|
||||||
unless client.nil?
|
unless client.nil?
|
||||||
|
@ -170,7 +170,7 @@ rescue e
|
||||||
end
|
end
|
||||||
|
|
||||||
def ws_cb_out(fd : Int32, pm : Pointer(LibIPC::Message))
|
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]
|
wsclient = Context.context.fd_to_websocket[fd]
|
||||||
|
|
||||||
message = IPC::Message.new pm
|
message = IPC::Message.new pm
|
||||||
|
@ -192,33 +192,28 @@ rescue e
|
||||||
end
|
end
|
||||||
|
|
||||||
def ws_cb_in(fd : Int32, pm : LibIPC::Message*)
|
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]
|
wsclient = Context.context.fd_to_websocket[fd]
|
||||||
|
|
||||||
puts
|
|
||||||
puts
|
|
||||||
puts "before run_once"
|
|
||||||
|
|
||||||
message = nil
|
message = nil
|
||||||
begin
|
begin
|
||||||
message = wsclient.run_once
|
message = wsclient.run_once
|
||||||
puts "after the run_once"
|
|
||||||
rescue e
|
rescue e
|
||||||
puts "#{CRED}run_once FAILED#{CRESET}: #{e}"
|
puts "#{CRED}run_once FAILED#{CRESET}: #{e}"
|
||||||
# Context.context.remove_fd fd
|
Context.context.remove_fd fd
|
||||||
return LibIPC::IPCCB::Error
|
return LibIPC::IPCCB::Error
|
||||||
end
|
end
|
||||||
|
|
||||||
if wsclient.closed?
|
if wsclient.closed?
|
||||||
puts "#{CBLUE}client is closed#{CRESET}"
|
info "#{CBLUE}client is closed#{CRESET}"
|
||||||
# Context.context.remove_fd fd
|
Context.context.remove_fd fd
|
||||||
return LibIPC::IPCCB::Closing
|
return LibIPC::IPCCB::Closing
|
||||||
end
|
end
|
||||||
|
|
||||||
if message.nil?
|
if message.nil?
|
||||||
puts "#{CRED}message is nil#{CRESET}"
|
puts "#{CRED}message is nil#{CRESET}"
|
||||||
# Context.context.remove_fd fd
|
Context.context.remove_fd fd
|
||||||
return LibIPC::IPCCB::Closing
|
return LibIPC::IPCCB::Closing
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -234,28 +229,28 @@ def ws_cb_in(fd : Int32, pm : LibIPC::Message*)
|
||||||
case message
|
case message
|
||||||
when WebSocket::Error
|
when WebSocket::Error
|
||||||
puts "#{CRED}An error occured#{CRESET}"
|
puts "#{CRED}An error occured#{CRESET}"
|
||||||
# Context.context.remove_fd fd
|
Context.context.remove_fd fd
|
||||||
return LibIPC::IPCCB::Error
|
return LibIPC::IPCCB::Error
|
||||||
when WebSocket::Ping
|
when WebSocket::Ping
|
||||||
puts "#{CBLUE}Received a ping message#{CRESET}"
|
puts "#{CBLUE}Received a ping message#{CRESET}"
|
||||||
# Context.context.remove_fd fd
|
Context.context.remove_fd fd
|
||||||
return LibIPC::IPCCB::Ignore
|
return LibIPC::IPCCB::Ignore
|
||||||
when WebSocket::Pong
|
when WebSocket::Pong
|
||||||
puts "#{CBLUE}Received a pong message#{CRESET}"
|
puts "#{CBLUE}Received a pong message#{CRESET}"
|
||||||
return LibIPC::IPCCB::Ignore
|
return LibIPC::IPCCB::Ignore
|
||||||
when WebSocket::Close
|
when WebSocket::Close
|
||||||
puts "#{CBLUE}Received a close message#{CRESET}"
|
puts "#{CBLUE}Received a close message#{CRESET}"
|
||||||
# Context.context.remove_fd fd
|
Context.context.remove_fd fd
|
||||||
return LibIPC::IPCCB::Closing
|
return LibIPC::IPCCB::Closing
|
||||||
when WebSocket::NotFinal
|
when WebSocket::NotFinal
|
||||||
puts "#{CBLUE}Received only part of a message: NOT IMPLEMENTED#{CRESET}"
|
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
|
return LibIPC::IPCCB::Error
|
||||||
when Bytes
|
when Bytes
|
||||||
# TODO: when receiving a binary message
|
# TODO: when receiving a binary message
|
||||||
# we should test the format and maybe its content
|
# we should test the format and maybe its content
|
||||||
puts "#{CBLUE}Received a binary message: NOT IMPLEMENTED, YET#{CRESET}"
|
puts "#{CBLUE}Received a binary message: NOT IMPLEMENTED, YET#{CRESET}"
|
||||||
# Context.context.remove_fd fd
|
Context.context.remove_fd fd
|
||||||
return LibIPC::IPCCB::Error
|
return LibIPC::IPCCB::Error
|
||||||
else
|
else
|
||||||
puts "#{CRED}Received a websocket message with unknown type#{CRESET}"
|
puts "#{CRED}Received a websocket message with unknown type#{CRESET}"
|
||||||
|
@ -293,8 +288,8 @@ def main
|
||||||
service.timer = CLI.timer_delay
|
service.timer = CLI.timer_delay
|
||||||
|
|
||||||
service.loop do |event|
|
service.loop do |event|
|
||||||
info "current state of the context:"
|
# info "current state of the context:"
|
||||||
service.pp
|
# service.pp
|
||||||
case event
|
case event
|
||||||
when IPC::Event::Timer
|
when IPC::Event::Timer
|
||||||
info "#{CORANGE}IPC::Event::Timer#{CRESET}"
|
info "#{CORANGE}IPC::Event::Timer#{CRESET}"
|
||||||
|
|
Loading…
Reference in New Issue